aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/messagebus/latch.h
diff options
context:
space:
mode:
authornga <nga@yandex-team.ru>2022-02-10 16:48:09 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:48:09 +0300
commitc2a1af049e9deca890e9923abe64fe6c59060348 (patch)
treeb222e5ac2e2e98872661c51ccceee5da0d291e13 /library/cpp/messagebus/latch.h
parent1f553f46fb4f3c5eec631352cdd900a0709016af (diff)
downloadydb-c2a1af049e9deca890e9923abe64fe6c59060348.tar.gz
Restoring authorship annotation for <nga@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/messagebus/latch.h')
-rw-r--r--library/cpp/messagebus/latch.h92
1 files changed, 46 insertions, 46 deletions
diff --git a/library/cpp/messagebus/latch.h b/library/cpp/messagebus/latch.h
index d40aef27196..373f4c0e13b 100644
--- a/library/cpp/messagebus/latch.h
+++ b/library/cpp/messagebus/latch.h
@@ -1,53 +1,53 @@
-#pragma once
-
+#pragma once
+
#include <util/system/condvar.h>
-#include <util/system/mutex.h>
-
-class TLatch {
-private:
- // 0 for unlocked, 1 for locked
- TAtomic Locked;
- TMutex Mutex;
- TCondVar CondVar;
-
-public:
+#include <util/system/mutex.h>
+
+class TLatch {
+private:
+ // 0 for unlocked, 1 for locked
+ TAtomic Locked;
+ TMutex Mutex;
+ TCondVar CondVar;
+
+public:
TLatch()
: Locked(0)
{
}
-
- void Wait() {
- // optimistic path
- if (AtomicGet(Locked) == 0) {
- return;
- }
-
- TGuard<TMutex> guard(Mutex);
+
+ void Wait() {
+ // optimistic path
+ if (AtomicGet(Locked) == 0) {
+ return;
+ }
+
+ TGuard<TMutex> guard(Mutex);
while (AtomicGet(Locked) == 1) {
- CondVar.WaitI(Mutex);
- }
- }
-
- bool TryWait() {
- return AtomicGet(Locked) == 0;
- }
-
- void Unlock() {
- // optimistic path
- if (AtomicGet(Locked) == 0) {
- return;
- }
-
- TGuard<TMutex> guard(Mutex);
+ CondVar.WaitI(Mutex);
+ }
+ }
+
+ bool TryWait() {
+ return AtomicGet(Locked) == 0;
+ }
+
+ void Unlock() {
+ // optimistic path
+ if (AtomicGet(Locked) == 0) {
+ return;
+ }
+
+ TGuard<TMutex> guard(Mutex);
AtomicSet(Locked, 0);
- CondVar.BroadCast();
- }
-
- void Lock() {
- AtomicSet(Locked, 1);
- }
-
- bool IsLocked() {
- return AtomicGet(Locked);
- }
-};
+ CondVar.BroadCast();
+ }
+
+ void Lock() {
+ AtomicSet(Locked, 1);
+ }
+
+ bool IsLocked() {
+ return AtomicGet(Locked);
+ }
+};