| 34 | } |
| 35 | |
| 36 | void ConditionVariable::TimedWait(const TimeDelta& max_time) { |
| 37 | butil::ThreadRestrictions::AssertWaitAllowed(); |
| 38 | int64_t usecs = max_time.InMicroseconds(); |
| 39 | struct timespec relative_time; |
| 40 | relative_time.tv_sec = usecs / Time::kMicrosecondsPerSecond; |
| 41 | relative_time.tv_nsec = |
| 42 | (usecs % Time::kMicrosecondsPerSecond) * Time::kNanosecondsPerMicrosecond; |
| 43 | |
| 44 | #if defined(OS_MACOSX) |
| 45 | int rv = pthread_cond_timedwait_relative_np( |
| 46 | &condition_, user_mutex_, &relative_time); |
| 47 | #else |
| 48 | struct timeval now; |
| 49 | gettimeofday(&now, NULL); |
| 50 | struct timespec absolute_time; |
| 51 | absolute_time.tv_sec = now.tv_sec; |
| 52 | absolute_time.tv_nsec = now.tv_usec * Time::kNanosecondsPerMicrosecond; |
| 53 | |
| 54 | absolute_time.tv_sec += relative_time.tv_sec; |
| 55 | absolute_time.tv_nsec += relative_time.tv_nsec; |
| 56 | absolute_time.tv_sec += absolute_time.tv_nsec / Time::kNanosecondsPerSecond; |
| 57 | absolute_time.tv_nsec %= Time::kNanosecondsPerSecond; |
| 58 | DCHECK_GE(absolute_time.tv_sec, now.tv_sec); // Overflow paranoia |
| 59 | |
| 60 | int rv = pthread_cond_timedwait(&condition_, user_mutex_, &absolute_time); |
| 61 | #endif // OS_MACOSX |
| 62 | |
| 63 | DCHECK(rv == 0 || rv == ETIMEDOUT); |
| 64 | } |
| 65 | |
| 66 | void ConditionVariable::Broadcast() { |
| 67 | int rv = pthread_cond_broadcast(&condition_); |
nothing calls this directly
no test coverage detected