diff options
author | scroggo@google.com <scroggo@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-10-31 19:29:13 +0000 |
---|---|---|
committer | scroggo@google.com <scroggo@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-10-31 19:29:13 +0000 |
commit | 4d3c28158a65f9eac6b472dff29caa77b44f8134 (patch) | |
tree | 1c93fb4a955c852c70c3b4b1553d59ed1defb13e /src | |
parent | 0b7da433fe0eaa2833d1b2900715b013b36d93da (diff) |
Implement SkCondVar for windows.
Only works on Vista or later, since it uses condition variables.
Review URL: https://codereview.appspot.com/6812062
git-svn-id: http://skia.googlecode.com/svn/trunk@6225 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src')
-rw-r--r-- | src/utils/SkCondVar.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/utils/SkCondVar.cpp b/src/utils/SkCondVar.cpp index 8cbab58de2..5d001c0edd 100644 --- a/src/utils/SkCondVar.cpp +++ b/src/utils/SkCondVar.cpp @@ -8,31 +8,61 @@ #include "SkCondVar.h" 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); +#endif } SkCondVar::~SkCondVar() { +#ifdef SK_USE_POSIX_THREADS pthread_mutex_destroy(&fMutex); pthread_cond_destroy(&fCond); +#elif defined(SK_BUILD_FOR_WIN32) + DeleteCriticalSection(&fCriticalSection); + // No need to clean up fCondition. +#endif } void SkCondVar::lock() { +#ifdef SK_USE_POSIX_THREADS pthread_mutex_lock(&fMutex); +#elif defined(SK_BUILD_FOR_WIN32) + EnterCriticalSection(&fCriticalSection); +#endif } void SkCondVar::unlock() { +#ifdef SK_USE_POSIX_THREADS pthread_mutex_unlock(&fMutex); +#elif defined(SK_BUILD_FOR_WIN32) + LeaveCriticalSection(&fCriticalSection); +#endif } void SkCondVar::wait() { +#ifdef SK_USE_POSIX_THREADS pthread_cond_wait(&fCond, &fMutex); +#elif defined(SK_BUILD_FOR_WIN32) + SleepConditionVariableCS(&fCondition, &fCriticalSection, INFINITE); +#endif } void SkCondVar::signal() { +#ifdef SK_USE_POSIX_THREADS pthread_cond_signal(&fCond); +#elif defined(SK_BUILD_FOR_WIN32) + WakeConditionVariable(&fCondition); +#endif } void SkCondVar::broadcast() { +#ifdef SK_USE_POSIX_THREADS pthread_cond_broadcast(&fCond); +#elif defined(SK_BUILD_FOR_WIN32) + WakeAllConditionVariable(&fCondition); +#endif } |