2 * Copyright 2012 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #ifndef SkCondVar_DEFINED
9 #define SkCondVar_DEFINED
13 #ifdef SK_USE_POSIX_THREADS
15 #elif defined(SK_BUILD_FOR_WIN32)
18 #error "SkCondVar requires pthreads or Windows."
22 * Condition variable for blocking access to shared data from other threads and
23 * controlling which threads are awake.
25 * Currently only supported on platforms with posix threads and Windows Vista and above.
29 /** Returns true if it makes sense to create and use SkCondVars.
30 * You _MUST_ call this method and it must return true before creating any SkCondVars.
32 static bool Supported();
38 * Lock a mutex. Must be done before calling the other functions on this object.
48 * Pause the calling thread. Will be awoken when signal() or broadcast() is called.
49 * Must be called while lock() is held (but gives it up while waiting). Once awoken,
50 * the calling thread will hold the lock once again.
55 * Wake one thread waiting on this condition. Must be called while lock()
61 * Wake all threads waiting on this condition. Must be called while lock()
67 #ifdef SK_USE_POSIX_THREADS
68 pthread_mutex_t fMutex;
70 #elif defined(SK_BUILD_FOR_WIN32)
71 CRITICAL_SECTION fCriticalSection;
72 CONDITION_VARIABLE fCondition;