aboutsummaryrefslogtreecommitdiff
path: root/util/mutex.h
diff options
context:
space:
mode:
Diffstat (limited to 'util/mutex.h')
-rw-r--r--util/mutex.h23
1 files changed, 22 insertions, 1 deletions
diff --git a/util/mutex.h b/util/mutex.h
index d2f69e7..9787bfb 100644
--- a/util/mutex.h
+++ b/util/mutex.h
@@ -72,7 +72,7 @@ class Mutex {
MutexType mutex_;
// Catch the error of writing Mutex when intending MutexLock.
- Mutex(Mutex *ignored) {}
+ Mutex(Mutex *ignored);
// Disallow "evil" constructors
Mutex(const Mutex&);
void operator=(const Mutex&);
@@ -185,6 +185,27 @@ class WriterMutexLock {
#define ReaderMutexLock(x) COMPILE_ASSERT(0, rmutex_lock_decl_missing_var_name)
#define WriterMutexLock(x) COMPILE_ASSERT(0, wmutex_lock_decl_missing_var_name)
+// Provide safe way to declare and use global, linker-initialized mutex. Sigh.
+#ifdef HAVE_PTHREAD
+
+#define GLOBAL_MUTEX(name) \
+ static pthread_mutex_t (name) = PTHREAD_MUTEX_INITIALIZER
+#define GLOBAL_MUTEX_LOCK(name) \
+ pthread_mutex_lock(&(name))
+#define GLOBAL_MUTEX_UNLOCK(name) \
+ pthread_mutex_unlock(&(name))
+
+#else
+
+#define GLOBAL_MUTEX(name) \
+ static Mutex name
+#define GLOBAL_MUTEX_LOCK(name) \
+ name.Lock()
+#define GLOBAL_MUTEX_UNLOCK(name) \
+ name.Unlock()
+
+#endif
+
} // namespace re2
#endif /* #define RE2_UTIL_MUTEX_H_ */