about summary refs log tree commit diff
path: root/absl/synchronization/internal/waiter.h
diff options
context:
space:
mode:
authorAbseil Team <absl-team@google.com>2019-04-25T15·01-0700
committerMatt Calabrese <calabrese@x.team>2019-04-25T17·31-0400
commitcd86d0d20ab167c33b23d3875db68d1d4bad3a3b (patch)
tree13b92d2cd9f22326fa5cf9564ca056407569b79c /absl/synchronization/internal/waiter.h
parent33841c5c963aa9c3f096ef8e6c1e71624b941940 (diff)
Export of internal Abseil changes.
--
997d2a8d12d9395046b0bdfc2f206a0b2fe2f1f9 by Abseil Team <absl-team@google.com>:

Typo fix: IsHashCallble -> IsHashCallable

PiperOrigin-RevId: 245235915

--
2baa4df2e3284df925bfd728bab7d7bd60ae002e by Eric Fiselier <ericwf@google.com>:

Remove need for `Windows.h` header in `waiter.h`

Ideally we never want to drag in `windows.h` because it's non-modular and hijacks global identifiers like `ERROR` and `OPAQUE`.

This patch changes our waiter implementation to store char buffers for `SRWLOCK` and `CONDITION_VARIABLE` instead of the types directly.

PiperOrigin-RevId: 245189428

--
33cfacd70c0d148d7590472dbcce38c93f2f7a34 by Matthew Brown <matthewbr@google.com>:

Internal change.

PiperOrigin-RevId: 245092803
GitOrigin-RevId: 997d2a8d12d9395046b0bdfc2f206a0b2fe2f1f9
Change-Id: Icccd6cbe4b205096f6a71e114d135303ee4c1857
Diffstat (limited to 'absl/synchronization/internal/waiter.h')
-rw-r--r--absl/synchronization/internal/waiter.h20
1 files changed, 15 insertions, 5 deletions
diff --git a/absl/synchronization/internal/waiter.h b/absl/synchronization/internal/waiter.h
index 66b4bebfb532..a3e3124e4417 100644
--- a/absl/synchronization/internal/waiter.h
+++ b/absl/synchronization/internal/waiter.h
@@ -18,9 +18,7 @@
 
 #include "absl/base/config.h"
 
-#ifdef _WIN32
-#include <windows.h>
-#else
+#ifndef _WIN32
 #include <pthread.h>
 #endif
 
@@ -123,8 +121,20 @@ class Waiter {
   // primivitives.  We are using SRWLOCK and CONDITION_VARIABLE
   // because they don't require a destructor to release system
   // resources.
-  SRWLOCK mu_;
-  CONDITION_VARIABLE cv_;
+  //
+  // However, we can't include Windows.h in our headers, so we use aligned
+  // storage buffers to define the storage.
+  using SRWLockStorage =
+      typename std::aligned_storage<sizeof(void*), alignof(void*)>::type;
+  using ConditionVariableStorage =
+      typename std::aligned_storage<sizeof(void*), alignof(void*)>::type;
+
+  // WinHelper - Used to define utilities for accessing the lock and
+  // condition variable storage once the types are complete.
+  class WinHelper;
+
+  SRWLockStorage mu_storage_;
+  ConditionVariableStorage cv_storage_;
   std::atomic<int> waiter_count_;
   std::atomic<int> wakeup_count_;