about summary refs log tree commit diff
path: root/absl/synchronization
diff options
context:
space:
mode:
Diffstat (limited to 'absl/synchronization')
-rw-r--r--absl/synchronization/internal/create_thread_identity.cc1
-rw-r--r--absl/synchronization/internal/graphcycles.cc1
-rw-r--r--absl/synchronization/lifetime_test.cc41
-rw-r--r--absl/synchronization/mutex.cc1
-rw-r--r--absl/synchronization/mutex.h1
5 files changed, 44 insertions, 1 deletions
diff --git a/absl/synchronization/internal/create_thread_identity.cc b/absl/synchronization/internal/create_thread_identity.cc
index 0134a4399b42..e7a65cd884a1 100644
--- a/absl/synchronization/internal/create_thread_identity.cc
+++ b/absl/synchronization/internal/create_thread_identity.cc
@@ -21,6 +21,7 @@
 
 #include <string.h>
 
+#include "absl/base/attributes.h"
 #include "absl/base/internal/spinlock.h"
 #include "absl/base/internal/thread_identity.h"
 #include "absl/synchronization/internal/per_thread_sem.h"
diff --git a/absl/synchronization/internal/graphcycles.cc b/absl/synchronization/internal/graphcycles.cc
index d7ae0cf320d7..9bc9c8a0f00d 100644
--- a/absl/synchronization/internal/graphcycles.cc
+++ b/absl/synchronization/internal/graphcycles.cc
@@ -28,6 +28,7 @@
 // (2) When a new edge (x->y) is inserted, do nothing if rank[x] < rank[y].
 // (3) Otherwise: adjust ranks in the neighborhood of x and y.
 
+#include "absl/base/attributes.h"
 // This file is a no-op if the required LowLevelAlloc support is missing.
 #include "absl/base/internal/low_level_alloc.h"
 #ifndef ABSL_LOW_LEVEL_ALLOC_MISSING
diff --git a/absl/synchronization/lifetime_test.cc b/absl/synchronization/lifetime_test.cc
index 6aea60e1362f..a3e2701f9208 100644
--- a/absl/synchronization/lifetime_test.cc
+++ b/absl/synchronization/lifetime_test.cc
@@ -69,8 +69,22 @@ void ThreadTwo(absl::Mutex* mutex, absl::CondVar* condvar,
 }
 
 // Launch thread 1 and thread 2, and block on their completion.
+// If any of 'mutex', 'condvar', or 'notification' is nullptr, use a locally
+// constructed instance instead.
 void RunTests(absl::Mutex* mutex, absl::CondVar* condvar,
               absl::Notification* notification) {
+  absl::Mutex default_mutex;
+  absl::CondVar default_condvar;
+  absl::Notification default_notification;
+  if (!mutex) {
+    mutex = &default_mutex;
+  }
+  if (!condvar) {
+    condvar = &default_condvar;
+  }
+  if (!notification) {
+    notification = &default_notification;
+  }
   bool state = false;
   std::thread thread_one(ThreadOne, mutex, condvar, notification, &state);
   std::thread thread_two(ThreadTwo, mutex, condvar, notification, &state);
@@ -85,6 +99,33 @@ void TestLocals() {
   RunTests(&mutex, &condvar, &notification);
 }
 
+// Global variables during start and termination
+//
+// In a translation unit, static storage duration variables are initialized in
+// the order of their definitions, and destroyed in the reverse order of their
+// definitions.  We can use this to arrange for tests to be run on these objects
+// before they are created, and after they are destroyed.
+
+class ConstructorTestRunner {
+ public:
+  ConstructorTestRunner(absl::Mutex* mutex, absl::CondVar* condvar,
+                        absl::Notification* notification) {
+    RunTests(mutex, condvar, notification);
+  }
+};
+
+class DestructorTestRunner {
+ public:
+  DestructorTestRunner(absl::Mutex* mutex, absl::CondVar* condvar,
+                       absl::Notification* notification)
+      : mutex_(mutex), condvar_(condvar), notification_(notification) {}
+  ~DestructorTestRunner() { RunTests(mutex_, condvar_, notification_); }
+ private:
+  absl::Mutex* mutex_;
+  absl::CondVar* condvar_;
+  absl::Notification* notification_;
+};
+
 }  // namespace
 
 int main() {
diff --git a/absl/synchronization/mutex.cc b/absl/synchronization/mutex.cc
index 32d9e3c2f426..b2aa743977ac 100644
--- a/absl/synchronization/mutex.cc
+++ b/absl/synchronization/mutex.cc
@@ -249,7 +249,6 @@ static const struct {
   { 0,                           "Signal on " },
   { 0,                           "SignalAll on " },
 };
-
 static absl::base_internal::SpinLock synch_event_mu(
     absl::base_internal::kLinkerInitialized);
 // protects synch_event
diff --git a/absl/synchronization/mutex.h b/absl/synchronization/mutex.h
index bad37c59441e..26ac7f619bff 100644
--- a/absl/synchronization/mutex.h
+++ b/absl/synchronization/mutex.h
@@ -875,6 +875,7 @@ class SCOPED_LOCKABLE ReleasableMutexLock {
 
 #ifdef ABSL_INTERNAL_USE_NONPROD_MUTEX
 #else
+
 inline CondVar::CondVar() : cv_(0) {}
 #endif