summaryrefslogtreecommitdiff
path: root/absl/synchronization/internal/waiter.h
diff options
context:
space:
mode:
Diffstat (limited to 'absl/synchronization/internal/waiter.h')
-rw-r--r--absl/synchronization/internal/waiter.h27
1 files changed, 13 insertions, 14 deletions
diff --git a/absl/synchronization/internal/waiter.h b/absl/synchronization/internal/waiter.h
index c2389700..cac81d5f 100644
--- a/absl/synchronization/internal/waiter.h
+++ b/absl/synchronization/internal/waiter.h
@@ -58,14 +58,15 @@ namespace synchronization_internal {
// Waiter is an OS-specific semaphore.
class Waiter {
public:
- // No constructor, instances use the reserved space in ThreadIdentity.
- // All initialization logic belongs in `Init()`.
- Waiter() = delete;
+ // Prepare any data to track waits.
+ Waiter();
+
+ // Not copyable or movable
Waiter(const Waiter&) = delete;
Waiter& operator=(const Waiter&) = delete;
- // Prepare any data to track waits.
- void Init();
+ // Destroy any data to track waits.
+ ~Waiter();
// Blocks the calling thread until a matching call to `Post()` or
// `t` has passed. Returns `true` if woken (`Post()` called),
@@ -122,13 +123,8 @@ class Waiter {
std::atomic<int> wakeups_;
#elif ABSL_WAITER_MODE == ABSL_WAITER_MODE_WIN32
- // The Windows API has lots of choices for synchronization
- // primivitives. We are using SRWLOCK and CONDITION_VARIABLE
- // because they don't require a destructor to release system
- // resources.
- //
- // However, we can't include Windows.h in our headers, so we use aligned
- // storage buffers to define the storage.
+ // We can't include Windows.h in our headers, so we use aligned storage
+ // buffers to define the storage of SRWLOCK and CONDITION_VARIABLE.
using SRWLockStorage =
typename std::aligned_storage<sizeof(void*), alignof(void*)>::type;
using ConditionVariableStorage =
@@ -138,10 +134,13 @@ class Waiter {
// condition variable storage once the types are complete.
class WinHelper;
+ // REQUIRES: WinHelper::GetLock(this) must be held.
+ void InternalCondVarPoke();
+
SRWLockStorage mu_storage_;
ConditionVariableStorage cv_storage_;
- std::atomic<int> waiter_count_;
- std::atomic<int> wakeup_count_;
+ int waiter_count_;
+ int wakeup_count_;
#else
#error Unknown ABSL_WAITER_MODE