summaryrefslogtreecommitdiffstats
path: root/library/cpp/actors/util/threadparkpad.cpp
diff options
context:
space:
mode:
authorddoarn <[email protected]>2022-02-10 16:49:52 +0300
committerDaniil Cherednik <[email protected]>2022-02-10 16:49:52 +0300
commit0783fe3f48d91a3b741ce2ea32b11fbfc1637e7e (patch)
tree6d6a79d83e5003eaf4d45cac346113c1137cb886 /library/cpp/actors/util/threadparkpad.cpp
parent9541fc30d6f0877db9ff199a16f7fc2505d46a5c (diff)
Restoring authorship annotation for <[email protected]>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/actors/util/threadparkpad.cpp')
-rw-r--r--library/cpp/actors/util/threadparkpad.cpp88
1 files changed, 44 insertions, 44 deletions
diff --git a/library/cpp/actors/util/threadparkpad.cpp b/library/cpp/actors/util/threadparkpad.cpp
index 74069ff15bf..88813e270c3 100644
--- a/library/cpp/actors/util/threadparkpad.cpp
+++ b/library/cpp/actors/util/threadparkpad.cpp
@@ -1,15 +1,15 @@
-#include "threadparkpad.h"
-#include <util/system/winint.h>
-
-#ifdef _linux_
-
-#include "futex.h"
-
-namespace NActors {
+#include "threadparkpad.h"
+#include <util/system/winint.h>
+
+#ifdef _linux_
+
+#include "futex.h"
+
+namespace NActors {
class TThreadParkPad::TImpl {
volatile bool Interrupted;
int Futex;
-
+
public:
TImpl()
: Interrupted(false)
@@ -18,39 +18,39 @@ namespace NActors {
}
~TImpl() {
}
-
+
bool Park() noexcept {
__atomic_fetch_sub(&Futex, 1, __ATOMIC_SEQ_CST);
while (__atomic_load_n(&Futex, __ATOMIC_ACQUIRE) == -1)
SysFutex(&Futex, FUTEX_WAIT_PRIVATE, -1, nullptr, nullptr, 0);
return IsInterrupted();
}
-
+
void Unpark() noexcept {
const int old = __atomic_fetch_add(&Futex, 1, __ATOMIC_SEQ_CST);
if (old == -1)
SysFutex(&Futex, FUTEX_WAKE_PRIVATE, -1, nullptr, nullptr, 0);
}
-
+
void Interrupt() noexcept {
__atomic_store_n(&Interrupted, true, __ATOMIC_SEQ_CST);
Unpark();
}
-
+
bool IsInterrupted() const noexcept {
return __atomic_load_n(&Interrupted, __ATOMIC_ACQUIRE);
}
};
-
-#elif defined _win32_
+
+#elif defined _win32_
#include <util/generic/bt_exception.h>
-#include <util/generic/yexception.h>
-
-namespace NActors {
+#include <util/generic/yexception.h>
+
+namespace NActors {
class TThreadParkPad::TImpl {
TAtomic Interrupted;
HANDLE EvHandle;
-
+
public:
TImpl()
: Interrupted(false)
@@ -63,35 +63,35 @@ namespace NActors {
if (EvHandle)
::CloseHandle(EvHandle);
}
-
+
bool Park() noexcept {
::WaitForSingleObject(EvHandle, INFINITE);
return AtomicGet(Interrupted);
}
-
+
void Unpark() noexcept {
::SetEvent(EvHandle);
}
-
+
void Interrupt() noexcept {
AtomicSet(Interrupted, true);
Unpark();
}
-
+
bool IsInterrupted() const noexcept {
return AtomicGet(Interrupted);
}
};
-
-#else
-
-#include <util/system/event.h>
-
-namespace NActors {
+
+#else
+
+#include <util/system/event.h>
+
+namespace NActors {
class TThreadParkPad::TImpl {
TAtomic Interrupted;
TSystemEvent Ev;
-
+
public:
TImpl()
: Interrupted(false)
@@ -100,7 +100,7 @@ namespace NActors {
}
~TImpl() {
}
-
+
bool Park() noexcept {
Ev.Wait();
return AtomicGet(Interrupted);
@@ -123,26 +123,26 @@ namespace NActors {
TThreadParkPad::TThreadParkPad()
: Impl(new TThreadParkPad::TImpl())
- {
- }
+ {
+ }
TThreadParkPad::~TThreadParkPad() {
- }
-
+ }
+
bool TThreadParkPad::Park() noexcept {
return Impl->Park();
- }
-
+ }
+
void TThreadParkPad::Unpark() noexcept {
Impl->Unpark();
- }
-
+ }
+
void TThreadParkPad::Interrupt() noexcept {
Impl->Interrupt();
- }
-
+ }
+
bool TThreadParkPad::Interrupted() const noexcept {
return Impl->IsInterrupted();
- }
-
-}
+ }
+
+}