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

Unified Diff: src/utils/SkCondVar.cpp

Issue 700683002: Manually load CONDITION_VARIABLE methods on Windows, checking for failure (XP). (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: winapi Created 6 years, 1 month 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 | « src/utils/SkCondVar.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/utils/SkCondVar.cpp
diff --git a/src/utils/SkCondVar.cpp b/src/utils/SkCondVar.cpp
index 5d001c0eddbf14b1cdf4affffd35e33eae47e075..ce5ef3e2ebd7ce2e52ededc41cae28c9e4c9011e 100644
--- a/src/utils/SkCondVar.cpp
+++ b/src/utils/SkCondVar.cpp
@@ -7,13 +7,47 @@
#include "SkCondVar.h"
+#if defined(SK_BUILD_FOR_WIN32)
+ static void (WINAPI *initialize_condition_variable)(PCONDITION_VARIABLE);
+ static BOOL (WINAPI *sleep_condition_variable)(PCONDITION_VARIABLE, PCRITICAL_SECTION, DWORD);
+ static void (WINAPI *wake_condition_variable)(PCONDITION_VARIABLE);
+ static void (WINAPI *wake_all_condition_variable)(PCONDITION_VARIABLE);
+
+ template <typename T>
+ static void set_fn_ptr(T* ptr, FARPROC fn) { *ptr = reinterpret_cast<T>(fn); }
+#endif
+
+bool SkCondVar::Supported() {
+#ifdef SK_USE_POSIX_THREADS
+ return true;
+#elif defined(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,
+ GetProcAddress(kernel32, "InitializeConditionVariable"));
+ set_fn_ptr(&sleep_condition_variable,
+ GetProcAddress(kernel32, "SleepConditionVariableCS"));
+ set_fn_ptr(&wake_condition_variable,
+ GetProcAddress(kernel32, "WakeConditionVariable"));
+ set_fn_ptr(&wake_all_condition_variable,
+ GetProcAddress(kernel32, "WakeAllConditionVariable"));
+ return initialize_condition_variable
+ && sleep_condition_variable
+ && wake_condition_variable
+ && wake_all_condition_variable;
+#else
+ return false;
+#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)
InitializeCriticalSection(&fCriticalSection);
- InitializeConditionVariable(&fCondition);
+ SkASSERT(initialize_condition_variable);
+ initialize_condition_variable(&fCondition);
#endif
}
@@ -47,7 +81,8 @@ void SkCondVar::wait() {
#ifdef SK_USE_POSIX_THREADS
pthread_cond_wait(&fCond, &fMutex);
#elif defined(SK_BUILD_FOR_WIN32)
- SleepConditionVariableCS(&fCondition, &fCriticalSection, INFINITE);
+ SkASSERT(sleep_condition_variable);
+ sleep_condition_variable(&fCondition, &fCriticalSection, INFINITE);
#endif
}
@@ -55,7 +90,8 @@ void SkCondVar::signal() {
#ifdef SK_USE_POSIX_THREADS
pthread_cond_signal(&fCond);
#elif defined(SK_BUILD_FOR_WIN32)
- WakeConditionVariable(&fCondition);
+ SkASSERT(wake_condition_variable);
+ wake_condition_variable(&fCondition);
#endif
}
@@ -63,6 +99,7 @@ void SkCondVar::broadcast() {
#ifdef SK_USE_POSIX_THREADS
pthread_cond_broadcast(&fCond);
#elif defined(SK_BUILD_FOR_WIN32)
- WakeAllConditionVariable(&fCondition);
+ SkASSERT(wake_all_condition_variable);
+ wake_all_condition_variable(&fCondition);
#endif
}
« no previous file with comments | « src/utils/SkCondVar.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698