aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/utils/SkCondVar.cpp
diff options
context:
space:
mode:
authorGravatar mtklein <mtklein@chromium.org>2015-01-21 19:51:27 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2015-01-21 19:51:27 -0800
commit4daa6f613cb7d8a3c07369af3e919ea65405ec55 (patch)
treec46b7e2e4ef4875532a0f1a37b3e95adfdfb3c53 /src/utils/SkCondVar.cpp
parent55e88b226ccb85d2c712a9e3e9e1f5bdcaac05ac (diff)
Don't require -DSK_USE_POSIX_THREADS.
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
Diffstat (limited to 'src/utils/SkCondVar.cpp')
-rw-r--r--src/utils/SkCondVar.cpp52
1 files changed, 25 insertions, 27 deletions
diff --git a/src/utils/SkCondVar.cpp b/src/utils/SkCondVar.cpp
index ce5ef3e2eb..12aca7613e 100644
--- a/src/utils/SkCondVar.cpp
+++ b/src/utils/SkCondVar.cpp
@@ -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
}