OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 } | 53 } |
54 | 54 |
55 EventTimerPosix::~EventTimerPosix() { | 55 EventTimerPosix::~EventTimerPosix() { |
56 StopTimer(); | 56 StopTimer(); |
57 pthread_cond_destroy(&cond_); | 57 pthread_cond_destroy(&cond_); |
58 pthread_mutex_destroy(&mutex_); | 58 pthread_mutex_destroy(&mutex_); |
59 } | 59 } |
60 | 60 |
61 // TODO(pbos): Make this void. | 61 // TODO(pbos): Make this void. |
62 bool EventTimerPosix::Set() { | 62 bool EventTimerPosix::Set() { |
63 CHECK_EQ(0, pthread_mutex_lock(&mutex_)); | 63 RTC_CHECK_EQ(0, pthread_mutex_lock(&mutex_)); |
64 event_set_ = true; | 64 event_set_ = true; |
65 pthread_cond_signal(&cond_); | 65 pthread_cond_signal(&cond_); |
66 pthread_mutex_unlock(&mutex_); | 66 pthread_mutex_unlock(&mutex_); |
67 return true; | 67 return true; |
68 } | 68 } |
69 | 69 |
70 EventTypeWrapper EventTimerPosix::Wait(unsigned long timeout) { | 70 EventTypeWrapper EventTimerPosix::Wait(unsigned long timeout) { |
71 int ret_val = 0; | 71 int ret_val = 0; |
72 CHECK_EQ(0, pthread_mutex_lock(&mutex_)); | 72 RTC_CHECK_EQ(0, pthread_mutex_lock(&mutex_)); |
73 | 73 |
74 if (!event_set_) { | 74 if (!event_set_) { |
75 if (WEBRTC_EVENT_INFINITE != timeout) { | 75 if (WEBRTC_EVENT_INFINITE != timeout) { |
76 timespec end_at; | 76 timespec end_at; |
77 #ifndef WEBRTC_MAC | 77 #ifndef WEBRTC_MAC |
78 #ifdef WEBRTC_CLOCK_TYPE_REALTIME | 78 #ifdef WEBRTC_CLOCK_TYPE_REALTIME |
79 clock_gettime(CLOCK_REALTIME, &end_at); | 79 clock_gettime(CLOCK_REALTIME, &end_at); |
80 #else | 80 #else |
81 clock_gettime(CLOCK_MONOTONIC, &end_at); | 81 clock_gettime(CLOCK_MONOTONIC, &end_at); |
82 #endif | 82 #endif |
(...skipping 13 matching lines...) Expand all Loading... |
96 end_at.tv_nsec -= E9; | 96 end_at.tv_nsec -= E9; |
97 } | 97 } |
98 while (ret_val == 0 && !event_set_) | 98 while (ret_val == 0 && !event_set_) |
99 ret_val = pthread_cond_timedwait(&cond_, &mutex_, &end_at); | 99 ret_val = pthread_cond_timedwait(&cond_, &mutex_, &end_at); |
100 } else { | 100 } else { |
101 while (ret_val == 0 && !event_set_) | 101 while (ret_val == 0 && !event_set_) |
102 ret_val = pthread_cond_wait(&cond_, &mutex_); | 102 ret_val = pthread_cond_wait(&cond_, &mutex_); |
103 } | 103 } |
104 } | 104 } |
105 | 105 |
106 DCHECK(ret_val == 0 || ret_val == ETIMEDOUT); | 106 RTC_DCHECK(ret_val == 0 || ret_val == ETIMEDOUT); |
107 | 107 |
108 // Reset and signal if set, regardless of why the thread woke up. | 108 // Reset and signal if set, regardless of why the thread woke up. |
109 if (event_set_) { | 109 if (event_set_) { |
110 ret_val = 0; | 110 ret_val = 0; |
111 event_set_ = false; | 111 event_set_ = false; |
112 } | 112 } |
113 pthread_mutex_unlock(&mutex_); | 113 pthread_mutex_unlock(&mutex_); |
114 | 114 |
115 return ret_val == 0 ? kEventSignaled : kEventTimeout; | 115 return ret_val == 0 ? kEventSignaled : kEventTimeout; |
116 } | 116 } |
117 | 117 |
118 EventTypeWrapper EventTimerPosix::Wait(timespec* end_at) { | 118 EventTypeWrapper EventTimerPosix::Wait(timespec* end_at) { |
119 int ret_val = 0; | 119 int ret_val = 0; |
120 CHECK_EQ(0, pthread_mutex_lock(&mutex_)); | 120 RTC_CHECK_EQ(0, pthread_mutex_lock(&mutex_)); |
121 | 121 |
122 while (ret_val == 0 && !event_set_) | 122 while (ret_val == 0 && !event_set_) |
123 ret_val = pthread_cond_timedwait(&cond_, &mutex_, end_at); | 123 ret_val = pthread_cond_timedwait(&cond_, &mutex_, end_at); |
124 | 124 |
125 DCHECK(ret_val == 0 || ret_val == ETIMEDOUT); | 125 RTC_DCHECK(ret_val == 0 || ret_val == ETIMEDOUT); |
126 | 126 |
127 // Reset and signal if set, regardless of why the thread woke up. | 127 // Reset and signal if set, regardless of why the thread woke up. |
128 if (event_set_) { | 128 if (event_set_) { |
129 ret_val = 0; | 129 ret_val = 0; |
130 event_set_ = false; | 130 event_set_ = false; |
131 } | 131 } |
132 pthread_mutex_unlock(&mutex_); | 132 pthread_mutex_unlock(&mutex_); |
133 | 133 |
134 return ret_val == 0 ? kEventSignaled : kEventTimeout; | 134 return ret_val == 0 ? kEventSignaled : kEventTimeout; |
135 } | 135 } |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 } | 222 } |
223 timer_event_.reset(); | 223 timer_event_.reset(); |
224 | 224 |
225 // Set time to zero to force new reference time for the timer. | 225 // Set time to zero to force new reference time for the timer. |
226 memset(&created_at_, 0, sizeof(created_at_)); | 226 memset(&created_at_, 0, sizeof(created_at_)); |
227 count_ = 0; | 227 count_ = 0; |
228 return true; | 228 return true; |
229 } | 229 } |
230 | 230 |
231 } // namespace webrtc | 231 } // namespace webrtc |
OLD | NEW |