OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef SkCondVar_DEFINED | 8 #ifndef SkCondVar_DEFINED |
9 #define SkCondVar_DEFINED | 9 #define SkCondVar_DEFINED |
10 | 10 |
11 #include "SkTypes.h" | 11 #include "SkTypes.h" |
12 | 12 |
13 #ifdef SK_USE_POSIX_THREADS | 13 #ifdef SK_BUILD_FOR_WIN32 |
14 #include <pthread.h> | |
15 #elif defined(SK_BUILD_FOR_WIN32) | |
16 #include <windows.h> | 14 #include <windows.h> |
17 #else | 15 #else |
18 #error "SkCondVar requires pthreads or Windows." | 16 #include <pthread.h> |
19 #endif | 17 #endif |
20 | 18 |
21 /** | 19 /** |
22 * Condition variable for blocking access to shared data from other threads and | 20 * Condition variable for blocking access to shared data from other threads and |
23 * controlling which threads are awake. | 21 * controlling which threads are awake. |
24 * | 22 * |
25 * Currently only supported on platforms with posix threads and Windows Vista an
d above. | 23 * Currently only supported on platforms with posix threads and Windows Vista an
d above. |
26 */ | 24 */ |
27 class SkCondVar { | 25 class SkCondVar { |
28 public: | 26 public: |
(...skipping 28 matching lines...) Expand all Loading... |
57 */ | 55 */ |
58 void signal(); | 56 void signal(); |
59 | 57 |
60 /** | 58 /** |
61 * Wake all threads waiting on this condition. Must be called while lock() | 59 * Wake all threads waiting on this condition. Must be called while lock() |
62 * is held. | 60 * is held. |
63 */ | 61 */ |
64 void broadcast(); | 62 void broadcast(); |
65 | 63 |
66 private: | 64 private: |
67 #ifdef SK_USE_POSIX_THREADS | 65 #ifdef SK_BUILD_FOR_WIN32 |
| 66 CRITICAL_SECTION fCriticalSection; |
| 67 CONDITION_VARIABLE fCondition; |
| 68 #else |
68 pthread_mutex_t fMutex; | 69 pthread_mutex_t fMutex; |
69 pthread_cond_t fCond; | 70 pthread_cond_t fCond; |
70 #elif defined(SK_BUILD_FOR_WIN32) | |
71 CRITICAL_SECTION fCriticalSection; | |
72 CONDITION_VARIABLE fCondition; | |
73 #endif | 71 #endif |
74 }; | 72 }; |
75 | 73 |
76 #endif | 74 #endif |
OLD | NEW |