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 THREAD_CONDITION_H_ | 5 #ifndef GTEST_PPAPI_THREAD_CONDITION_H_ |
6 #define THREAD_CONDITION_H_ | 6 #define GTEST_PPAPI_THREAD_CONDITION_H_ |
7 | 7 |
8 #include "c_salt/threading/pthread_ext.h" | 8 #include "gtest_ppapi/pthread_ext.h" |
9 | 9 |
10 struct timespec; | 10 struct timespec; |
11 | 11 |
12 namespace c_salt { | |
13 namespace threading { | |
14 // A wrapper class for condition signaling. Contains a mutex and condition | 12 // A wrapper class for condition signaling. Contains a mutex and condition |
15 // pair. | 13 // pair. |
16 class ThreadCondition { | 14 class ThreadCondition { |
17 public: | 15 public: |
18 // Initialize the mutex and the condition. | 16 // Initialize the mutex and the condition. |
19 ThreadCondition() { | 17 ThreadCondition() { |
20 pthread_mutex_init(&cond_mutex_, NULL); | 18 pthread_mutex_init(&cond_mutex_, NULL); |
21 pthread_cond_init(&condition_, NULL); | 19 pthread_cond_init(&condition_, NULL); |
22 } | 20 } |
23 | 21 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 // Same as Wait, but wait at most until abs_time. Returns false if the system | 60 // Same as Wait, but wait at most until abs_time. Returns false if the system |
63 // time exceeds abs_time before the condition is signaled. | 61 // time exceeds abs_time before the condition is signaled. |
64 bool TimedWait(struct timespec *abs_time) { | 62 bool TimedWait(struct timespec *abs_time) { |
65 return (pthread_cond_timedwait(&condition_, &cond_mutex_, abs_time) == 0); | 63 return (pthread_cond_timedwait(&condition_, &cond_mutex_, abs_time) == 0); |
66 } | 64 } |
67 | 65 |
68 private: | 66 private: |
69 pthread_mutex_t cond_mutex_; | 67 pthread_mutex_t cond_mutex_; |
70 pthread_cond_t condition_; | 68 pthread_cond_t condition_; |
71 }; | 69 }; |
72 } // namespace threading | |
73 } // namespace c_salt | |
74 | 70 |
75 #endif // THREAD_CONDITION_H_ | 71 #endif // GTEST_PPAPI_THREAD_CONDITION_H_ |
76 | |
OLD | NEW |