blob: 5d001c0eddbf14b1cdf4affffd35e33eae47e075 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
/*
* Copyright 2012 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#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
}
|