diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/utils/SkCondVar.h | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/include/utils/SkCondVar.h b/include/utils/SkCondVar.h index d2539e4b9e..15f16e662f 100644 --- a/include/utils/SkCondVar.h +++ b/include/utils/SkCondVar.h @@ -8,19 +8,38 @@ #ifndef SkCondVar_DEFINED #define SkCondVar_DEFINED +#ifdef SK_USE_POSIX_THREADS #include <pthread.h> +#elif defined(SK_BUILD_FOR_WIN32) +#include <Windows.h> +#endif +/** + * Condition variable for blocking access to shared data from other threads and + * controlling which threads are awake. + * + * Currently only supported on platforms with posix threads and Windows Vista and + * above. + */ class SkCondVar { public: SkCondVar(); ~SkCondVar(); + /** + * Lock a mutex. Must be done before calling the other functions on this object. + */ void lock(); + + /** + * Unlock the mutex. + */ void unlock(); /** - * Pause the calling thread. Will be awoken when signal() is called. - * Must be called while lock() is held (but gives it up while waiting). + * Pause the calling thread. Will be awoken when signal() or broadcast() is called. + * Must be called while lock() is held (but gives it up while waiting). Once awoken, + * the calling thread will hold the lock once again. */ void wait(); @@ -37,9 +56,13 @@ public: void broadcast(); private: - // FIXME: Make this independent of pthreads. +#ifdef SK_USE_POSIX_THREADS pthread_mutex_t fMutex; pthread_cond_t fCond; +#elif defined(SK_BUILD_FOR_WIN32) + CRITICAL_SECTION fCriticalSection; + CONDITION_VARIABLE fCondition; +#endif }; #endif |