OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONDITION_LOCK_H_ | 5 #ifndef GTEST_PPAPI_CONDITION_LOCK_H_ |
6 #define CONDITION_LOCK_H_ | 6 #define GTEST_PPAPI_CONDITION_LOCK_H_ |
7 | 7 |
8 #include <pthread.h> | 8 #include <pthread.h> |
9 | 9 |
10 namespace threading { | |
11 // Class to manage a lock associated with a specific value. The calling thread | 10 // Class to manage a lock associated with a specific value. The calling thread |
12 // can ask to acquire the lock only when the lock is in a certain condition. | 11 // can ask to acquire the lock only when the lock is in a certain condition. |
13 class ConditionLock { | 12 class ConditionLock { |
14 public: | 13 public: |
15 ConditionLock() : condition_value_(0) { | 14 ConditionLock() : condition_value_(0) { |
16 InitLock(); | 15 InitLock(); |
17 } | 16 } |
18 explicit ConditionLock(int32_t condition_value) | 17 explicit ConditionLock(int32_t condition_value) |
19 : condition_value_(condition_value) { | 18 : condition_value_(condition_value) { |
20 InitLock(); | 19 InitLock(); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 private: | 75 private: |
77 void InitLock() { | 76 void InitLock() { |
78 pthread_mutex_init(&condition_lock_, NULL); | 77 pthread_mutex_init(&condition_lock_, NULL); |
79 pthread_cond_init(&condition_condition_, NULL); | 78 pthread_cond_init(&condition_condition_, NULL); |
80 } | 79 } |
81 | 80 |
82 pthread_mutex_t condition_lock_; | 81 pthread_mutex_t condition_lock_; |
83 pthread_cond_t condition_condition_; | 82 pthread_cond_t condition_condition_; |
84 int32_t condition_value_; | 83 int32_t condition_value_; |
85 }; | 84 }; |
86 } // namespace threading | |
87 | 85 |
88 #endif // CONDITION_LOCK_H_ | 86 #endif // CONDITION_LOCK_H_ |
89 | |
OLD | NEW |