diff options
author | Anton Samokhvalov <pg83@yandex.ru> | 2022-02-10 16:45:15 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:15 +0300 |
commit | 72cb13b4aff9bc9cf22e49251bc8fd143f82538f (patch) | |
tree | da2c34829458c7d4e74bdfbdf85dff449e9e7fb8 /library/cpp/actors/util/threadparkpad.cpp | |
parent | 778e51ba091dc39e7b7fcab2b9cf4dbedfb6f2b5 (diff) | |
download | ydb-72cb13b4aff9bc9cf22e49251bc8fd143f82538f.tar.gz |
Restoring authorship annotation for Anton Samokhvalov <pg83@yandex.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/actors/util/threadparkpad.cpp')
-rw-r--r-- | library/cpp/actors/util/threadparkpad.cpp | 152 |
1 files changed, 76 insertions, 76 deletions
diff --git a/library/cpp/actors/util/threadparkpad.cpp b/library/cpp/actors/util/threadparkpad.cpp index 74069ff15b..471be44031 100644 --- a/library/cpp/actors/util/threadparkpad.cpp +++ b/library/cpp/actors/util/threadparkpad.cpp @@ -6,143 +6,143 @@ #include "futex.h" namespace NActors { - class TThreadParkPad::TImpl { - volatile bool Interrupted; - int Futex; - - public: - TImpl() - : Interrupted(false) - , Futex(0) - { - } - ~TImpl() { - } + class TThreadParkPad::TImpl { + volatile bool Interrupted; + int Futex; + + public: + TImpl() + : Interrupted(false) + , Futex(0) + { + } + ~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(); - } + __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); - } + 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(); - } + __atomic_store_n(&Interrupted, true, __ATOMIC_SEQ_CST); + Unpark(); + } bool IsInterrupted() const noexcept { - return __atomic_load_n(&Interrupted, __ATOMIC_ACQUIRE); - } - }; + return __atomic_load_n(&Interrupted, __ATOMIC_ACQUIRE); + } + }; #elif defined _win32_ #include <util/generic/bt_exception.h> #include <util/generic/yexception.h> namespace NActors { - class TThreadParkPad::TImpl { + class TThreadParkPad::TImpl { TAtomic Interrupted; - HANDLE EvHandle; - - public: - TImpl() - : Interrupted(false) - { - EvHandle = ::CreateEvent(0, false, false, 0); - if (!EvHandle) - ythrow TWithBackTrace<yexception>() << "::CreateEvent failed"; - } + HANDLE EvHandle; + + public: + TImpl() + : Interrupted(false) + { + EvHandle = ::CreateEvent(0, false, false, 0); + if (!EvHandle) + ythrow TWithBackTrace<yexception>() << "::CreateEvent failed"; + } ~TImpl() { - if (EvHandle) - ::CloseHandle(EvHandle); - } + if (EvHandle) + ::CloseHandle(EvHandle); + } bool Park() noexcept { - ::WaitForSingleObject(EvHandle, INFINITE); + ::WaitForSingleObject(EvHandle, INFINITE); return AtomicGet(Interrupted); - } + } void Unpark() noexcept { - ::SetEvent(EvHandle); - } + ::SetEvent(EvHandle); + } void Interrupt() noexcept { AtomicSet(Interrupted, true); - Unpark(); - } + Unpark(); + } bool IsInterrupted() const noexcept { return AtomicGet(Interrupted); - } - }; + } + }; #else #include <util/system/event.h> namespace NActors { - class TThreadParkPad::TImpl { + class TThreadParkPad::TImpl { TAtomic Interrupted; TSystemEvent Ev; - public: - TImpl() - : Interrupted(false) + public: + TImpl() + : Interrupted(false) , Ev(TSystemEvent::rAuto) - { - } + { + } ~TImpl() { - } + } bool Park() noexcept { - Ev.Wait(); + Ev.Wait(); return AtomicGet(Interrupted); - } - + } + void Unpark() noexcept { - Ev.Signal(); - } - + Ev.Signal(); + } + void Interrupt() noexcept { AtomicSet(Interrupted, true); - Unpark(); - } - + Unpark(); + } + bool IsInterrupted() const noexcept { return AtomicGet(Interrupted); - } - }; -#endif - - TThreadParkPad::TThreadParkPad() - : Impl(new TThreadParkPad::TImpl()) + } + }; +#endif + + TThreadParkPad::TThreadParkPad() + : Impl(new TThreadParkPad::TImpl()) { } - + TThreadParkPad::~TThreadParkPad() { } bool TThreadParkPad::Park() noexcept { - return Impl->Park(); + return Impl->Park(); } void TThreadParkPad::Unpark() noexcept { - Impl->Unpark(); + Impl->Unpark(); } void TThreadParkPad::Interrupt() noexcept { - Impl->Interrupt(); + Impl->Interrupt(); } bool TThreadParkPad::Interrupted() const noexcept { - return Impl->IsInterrupted(); + return Impl->IsInterrupted(); } } |