Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(101)

Unified Diff: third_party/re2/util/mutex.h

Issue 1516543002: Update re2 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: updated update instructions Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/re2/util/logging.cc ('k') | third_party/re2/util/pcre.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/re2/util/mutex.h
diff --git a/third_party/re2/util/mutex.h b/third_party/re2/util/mutex.h
index e321fae7360e036dfb7eee510e61cdb9d6e760c1..b479e481ff1a1d8f8d09f8814ccec37022f22f73 100644
--- a/third_party/re2/util/mutex.h
+++ b/third_party/re2/util/mutex.h
@@ -10,19 +10,40 @@
#ifndef RE2_UTIL_MUTEX_H_
#define RE2_UTIL_MUTEX_H_
+#include <stdlib.h>
+
+#if !defined(_WIN32)
+#include <unistd.h> // For POSIX options
+#endif
+
namespace re2 {
-#ifndef WIN32
-#define HAVE_PTHREAD 1
-#define HAVE_RWLOCK 1
+#if !defined(_WIN32)
+ // Possible values of POSIX options:
+ // -1 means not supported,
+ // 0 means maybe supported (query at runtime),
+ // >0 means supported.
+# if defined(_POSIX_THREADS) && _POSIX_THREADS > 0
+# define HAVE_PTHREAD 1
+# else
+# define HAVE_PTHREAD 0
+# endif
+# if defined(_POSIX_READER_WRITER_LOCKS) && _POSIX_READER_WRITER_LOCKS > 0
+# define HAVE_RWLOCK 1
+# else
+# define HAVE_RWLOCK 0
+# endif
+#else
+# define HAVE_PTHREAD 0
+# define HAVE_RWLOCK 0
#endif
#if defined(NO_THREADS)
typedef int MutexType; // to keep a lock-count
-#elif defined(HAVE_PTHREAD) && defined(HAVE_RWLOCK)
+#elif HAVE_PTHREAD && HAVE_RWLOCK
// Needed for pthread_rwlock_*. If it causes problems, you could take it
- // out, but then you'd have to unset HAVE_RWLOCK (at least on linux -- it
- // *does* cause problems for FreeBSD, or MacOSX, but isn't needed
+ // out, but then you'd have to set HAVE_RWLOCK to 0 (at least on linux --
+ // it *does* cause problems for FreeBSD, or MacOSX, but isn't needed
// for locking there.)
# ifdef __linux__
# undef _XOPEN_SOURCE
@@ -30,12 +51,12 @@ namespace re2 {
# endif
# include <pthread.h>
typedef pthread_rwlock_t MutexType;
-#elif defined(HAVE_PTHREAD)
+#elif HAVE_PTHREAD
# include <pthread.h>
typedef pthread_mutex_t MutexType;
-#elif defined(WIN32)
+#elif defined(_WIN32)
# ifndef WIN32_LEAN_AND_MEAN
-# define WIN32_LEAN_AND_MEAN // We only need minimal includes
+# define WIN32_LEAN_AND_MEAN // We only need minimal includes
# endif
# ifdef GMUTEX_TRYLOCK
// We need Windows NT or later for TryEnterCriticalSection(). If you
@@ -104,9 +125,8 @@ bool Mutex::TryLock() { if (mutex_) return false; Lock(); return true; }
void Mutex::ReaderLock() { assert(++mutex_ > 0); }
void Mutex::ReaderUnlock() { assert(mutex_-- > 0); }
-#elif defined(HAVE_PTHREAD) && defined(HAVE_RWLOCK)
+#elif HAVE_PTHREAD && HAVE_RWLOCK
-#include <stdlib.h> // for abort()
#define SAFE_PTHREAD(fncall) do { if ((fncall) != 0) abort(); } while (0)
Mutex::Mutex() { SAFE_PTHREAD(pthread_rwlock_init(&mutex_, NULL)); }
@@ -119,9 +139,8 @@ void Mutex::ReaderUnlock() { SAFE_PTHREAD(pthread_rwlock_unlock(&mutex_)); }
#undef SAFE_PTHREAD
-#elif defined(HAVE_PTHREAD)
+#elif HAVE_PTHREAD
-#include <stdlib.h> // for abort()
#define SAFE_PTHREAD(fncall) do { if ((fncall) != 0) abort(); } while (0)
Mutex::Mutex() { SAFE_PTHREAD(pthread_mutex_init(&mutex_, NULL)); }
@@ -133,7 +152,7 @@ void Mutex::ReaderLock() { Lock(); } // we don't have read-write locks
void Mutex::ReaderUnlock() { Unlock(); }
#undef SAFE_PTHREAD
-#elif defined(WIN32)
+#elif defined(_WIN32)
Mutex::Mutex() { InitializeCriticalSection(&mutex_); }
Mutex::~Mutex() { DeleteCriticalSection(&mutex_); }
@@ -190,7 +209,7 @@ class WriterMutexLock {
#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
+#if HAVE_PTHREAD
#define GLOBAL_MUTEX(name) \
static pthread_mutex_t (name) = PTHREAD_MUTEX_INITIALIZER
« no previous file with comments | « third_party/re2/util/logging.cc ('k') | third_party/re2/util/pcre.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698