Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(255)

Side by Side Diff: src/utils/SkCondVar.cpp

Issue 371853005: Move threadpool code from include/utils to tools/threadpool. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: gyp Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « include/utils/SkThreadPool.h ('k') | tests/OnceTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2012 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "SkCondVar.h"
9
10 SkCondVar::SkCondVar() {
11 #ifdef SK_USE_POSIX_THREADS
12 pthread_mutex_init(&fMutex, NULL /* default mutex attr */);
13 pthread_cond_init(&fCond, NULL /* default cond attr */);
14 #elif defined(SK_BUILD_FOR_WIN32)
15 InitializeCriticalSection(&fCriticalSection);
16 InitializeConditionVariable(&fCondition);
17 #endif
18 }
19
20 SkCondVar::~SkCondVar() {
21 #ifdef SK_USE_POSIX_THREADS
22 pthread_mutex_destroy(&fMutex);
23 pthread_cond_destroy(&fCond);
24 #elif defined(SK_BUILD_FOR_WIN32)
25 DeleteCriticalSection(&fCriticalSection);
26 // No need to clean up fCondition.
27 #endif
28 }
29
30 void SkCondVar::lock() {
31 #ifdef SK_USE_POSIX_THREADS
32 pthread_mutex_lock(&fMutex);
33 #elif defined(SK_BUILD_FOR_WIN32)
34 EnterCriticalSection(&fCriticalSection);
35 #endif
36 }
37
38 void SkCondVar::unlock() {
39 #ifdef SK_USE_POSIX_THREADS
40 pthread_mutex_unlock(&fMutex);
41 #elif defined(SK_BUILD_FOR_WIN32)
42 LeaveCriticalSection(&fCriticalSection);
43 #endif
44 }
45
46 void SkCondVar::wait() {
47 #ifdef SK_USE_POSIX_THREADS
48 pthread_cond_wait(&fCond, &fMutex);
49 #elif defined(SK_BUILD_FOR_WIN32)
50 SleepConditionVariableCS(&fCondition, &fCriticalSection, INFINITE);
51 #endif
52 }
53
54 void SkCondVar::signal() {
55 #ifdef SK_USE_POSIX_THREADS
56 pthread_cond_signal(&fCond);
57 #elif defined(SK_BUILD_FOR_WIN32)
58 WakeConditionVariable(&fCondition);
59 #endif
60 }
61
62 void SkCondVar::broadcast() {
63 #ifdef SK_USE_POSIX_THREADS
64 pthread_cond_broadcast(&fCond);
65 #elif defined(SK_BUILD_FOR_WIN32)
66 WakeAllConditionVariable(&fCondition);
67 #endif
68 }
OLDNEW
« no previous file with comments | « include/utils/SkThreadPool.h ('k') | tests/OnceTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698