Don't require -DSK_USE_POSIX_THREADS.
authormtklein <mtklein@chromium.org>
Thu, 22 Jan 2015 03:51:27 +0000 (19:51 -0800)
committerCommit bot <commit-bot@chromium.org>
Thu, 22 Jan 2015 03:51:27 +0000 (19:51 -0800)
To compile SkCondVar, we already require either pthreads or Windows.  This
simplifies that code to not need SK_USE_POSIX_THREADS to be explicitly defined.
We'll just look to see if we're targeting Windows, and if not, assume pthreads.

Both before and after this CL, that code will fail to compile if we're not on
Windows and don't have pthreads.

BUG=skia:

Review URL: https://codereview.chromium.org/869443003

gyp/common_conditions.gypi
src/core/SkPixelRef.cpp
src/utils/SkCondVar.cpp
src/utils/SkCondVar.h

index 32335f9416e25fa0f7b586ee6895cbd86538fad6..0fbeb09c7840f2ba60d9f425d23146c9cd02935c 100644 (file)
       },
     ],
 
-    # We can POD-style initialization of static mutexes to avoid generating
-    # static initializers if we're using a pthread-compatible thread interface.
-    [ 'skia_os != "win"', {
-      'defines': [
-        'SK_USE_POSIX_THREADS',
-      ],
-    }],
-
     [ 'skia_moz2d', {
       'defines': [
         # add flags here (e.g. SK_SUPPORT_LEGACY_...) needed by moz2d
index a2c37c6e72f92de7ce16d301632dacdb6dbb1fbf..bb4a5eff8882f6127d56ec8a0c9637b02b1639e0 100644 (file)
@@ -8,8 +8,14 @@
 #include "SkPixelRef.h"
 #include "SkThread.h"
 
-#ifdef SK_USE_POSIX_THREADS
+#ifdef SK_BUILD_FOR_WIN32
+    // We don't have SK_BASE_MUTEX_INIT on Windows.
 
+    // must be a power-of-2. undef to just use 1 mutex
+    #define PIXELREF_MUTEX_RING_COUNT       32
+    static SkBaseMutex gPixelRefMutexRing[PIXELREF_MUTEX_RING_COUNT];
+
+#else
     static SkBaseMutex gPixelRefMutexRing[] = {
         SK_BASE_MUTEX_INIT, SK_BASE_MUTEX_INIT,
         SK_BASE_MUTEX_INIT, SK_BASE_MUTEX_INIT,
         SK_BASE_MUTEX_INIT, SK_BASE_MUTEX_INIT,
         SK_BASE_MUTEX_INIT, SK_BASE_MUTEX_INIT,
     };
-
     // must be a power-of-2. undef to just use 1 mutex
     #define PIXELREF_MUTEX_RING_COUNT SK_ARRAY_COUNT(gPixelRefMutexRing)
 
-#else // not pthreads
-
-    // must be a power-of-2. undef to just use 1 mutex
-    #define PIXELREF_MUTEX_RING_COUNT       32
-    static SkBaseMutex gPixelRefMutexRing[PIXELREF_MUTEX_RING_COUNT];
-
 #endif
 
 static SkBaseMutex* get_default_mutex() {
index ce5ef3e2ebd7ce2e52ededc41cae28c9e4c9011e..12aca7613e0a39fc0871123abbbd3eeb528fdbe4 100644 (file)
@@ -18,9 +18,7 @@
 #endif
 
 bool SkCondVar::Supported() {
-#ifdef SK_USE_POSIX_THREADS
-    return true;
-#elif defined(SK_BUILD_FOR_WIN32)
+#ifdef SK_BUILD_FOR_WIN32
     // If we're >= Vista we'll find these functions.  Otherwise (XP) SkCondVar is not supported.
     HMODULE kernel32 = GetModuleHandleA("kernel32.dll");
     set_fn_ptr(&initialize_condition_variable,
@@ -36,70 +34,70 @@ bool SkCondVar::Supported() {
         && wake_condition_variable
         && wake_all_condition_variable;
 #else
-    return false;
+    return true;
 #endif
 }
 
 SkCondVar::SkCondVar() {
-#ifdef SK_USE_POSIX_THREADS
-    pthread_mutex_init(&fMutex, NULL /* default mutex attr */);
-    pthread_cond_init(&fCond, NULL /* default cond attr */);
-#elif defined(SK_BUILD_FOR_WIN32)
+#ifdef SK_BUILD_FOR_WIN32
     InitializeCriticalSection(&fCriticalSection);
     SkASSERT(initialize_condition_variable);
     initialize_condition_variable(&fCondition);
+#else
+    pthread_mutex_init(&fMutex, NULL /* default mutex attr */);
+    pthread_cond_init(&fCond, NULL /* default cond attr */);
 #endif
 }
 
 SkCondVar::~SkCondVar() {
-#ifdef SK_USE_POSIX_THREADS
-    pthread_mutex_destroy(&fMutex);
-    pthread_cond_destroy(&fCond);
-#elif defined(SK_BUILD_FOR_WIN32)
+#ifdef SK_BUILD_FOR_WIN32
     DeleteCriticalSection(&fCriticalSection);
     // No need to clean up fCondition.
+#else
+    pthread_mutex_destroy(&fMutex);
+    pthread_cond_destroy(&fCond);
 #endif
 }
 
 void SkCondVar::lock() {
-#ifdef SK_USE_POSIX_THREADS
-    pthread_mutex_lock(&fMutex);
-#elif defined(SK_BUILD_FOR_WIN32)
+#ifdef SK_BUILD_FOR_WIN32
     EnterCriticalSection(&fCriticalSection);
+#else
+    pthread_mutex_lock(&fMutex);
 #endif
 }
 
 void SkCondVar::unlock() {
-#ifdef SK_USE_POSIX_THREADS
-    pthread_mutex_unlock(&fMutex);
-#elif defined(SK_BUILD_FOR_WIN32)
+#ifdef SK_BUILD_FOR_WIN32
     LeaveCriticalSection(&fCriticalSection);
+#else
+    pthread_mutex_unlock(&fMutex);
 #endif
 }
 
 void SkCondVar::wait() {
-#ifdef SK_USE_POSIX_THREADS
-    pthread_cond_wait(&fCond, &fMutex);
-#elif defined(SK_BUILD_FOR_WIN32)
+#ifdef SK_BUILD_FOR_WIN32
     SkASSERT(sleep_condition_variable);
     sleep_condition_variable(&fCondition, &fCriticalSection, INFINITE);
+#else
+    pthread_cond_wait(&fCond, &fMutex);
 #endif
 }
 
 void SkCondVar::signal() {
-#ifdef SK_USE_POSIX_THREADS
-    pthread_cond_signal(&fCond);
-#elif defined(SK_BUILD_FOR_WIN32)
+#ifdef SK_BUILD_FOR_WIN32
     SkASSERT(wake_condition_variable);
     wake_condition_variable(&fCondition);
+#else
+    pthread_cond_signal(&fCond);
 #endif
 }
 
 void SkCondVar::broadcast() {
-#ifdef SK_USE_POSIX_THREADS
-    pthread_cond_broadcast(&fCond);
-#elif defined(SK_BUILD_FOR_WIN32)
+#ifdef SK_BUILD_FOR_WIN32
     SkASSERT(wake_all_condition_variable);
     wake_all_condition_variable(&fCondition);
+#else
+    pthread_cond_broadcast(&fCond);
 #endif
 }
index 7f4225c66ac1d9550e428efc8ab43979ec3f3911..0a9f94f0abebf44dcc322ad1cbfe59bf09907770 100644 (file)
 
 #include "SkTypes.h"
 
-#ifdef SK_USE_POSIX_THREADS
-    #include <pthread.h>
-#elif defined(SK_BUILD_FOR_WIN32)
+#ifdef SK_BUILD_FOR_WIN32
     #include <windows.h>
 #else
-    #error "SkCondVar requires pthreads or Windows."
+    #include <pthread.h>
 #endif
 
 /**
@@ -64,12 +62,12 @@ public:
     void broadcast();
 
 private:
-#ifdef SK_USE_POSIX_THREADS
-    pthread_mutex_t  fMutex;
-    pthread_cond_t   fCond;
-#elif defined(SK_BUILD_FOR_WIN32)
+#ifdef SK_BUILD_FOR_WIN32
     CRITICAL_SECTION   fCriticalSection;
     CONDITION_VARIABLE fCondition;
+#else
+    pthread_mutex_t  fMutex;
+    pthread_cond_t   fCond;
 #endif
 };