From 1a072f93eb4347ed94788dff880e7bb713498ad3 Mon Sep 17 00:00:00 2001 From: "tommi@webrtc.org" Date: Tue, 10 Feb 2015 12:27:48 +0000 Subject: [PATCH] Address comments from previous review round for rtc::Event. R=andresp@webrtc.org Review URL: https://webrtc-codereview.appspot.com/35049004 Cr-Commit-Position: refs/heads/master@{#8313} git-svn-id: http://webrtc.googlecode.com/svn/trunk@8313 4adac7df-926f-26a2-2b94-8c16560cd09d --- webrtc/base/event.cc | 16 ++++++++-------- webrtc/base/event.h | 5 ++++- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/webrtc/base/event.cc b/webrtc/base/event.cc index 7cd944329..999db3885 100644 --- a/webrtc/base/event.cc +++ b/webrtc/base/event.cc @@ -46,8 +46,8 @@ void Event::Reset() { ResetEvent(event_handle_); } -bool Event::Wait(int cms) { - DWORD ms = (cms == kForever) ? INFINITE : cms; +bool Event::Wait(int milliseconds) { + DWORD ms = (milliseconds == kForever) ? INFINITE : milliseconds; return (WaitForSingleObject(event_handle_, ms) == WAIT_OBJECT_0); } @@ -78,11 +78,11 @@ void Event::Reset() { pthread_mutex_unlock(&event_mutex_); } -bool Event::Wait(int cms) { +bool Event::Wait(int milliseconds) { pthread_mutex_lock(&event_mutex_); int error = 0; - if (cms != kForever) { + if (milliseconds != kForever) { // Converting from seconds and microseconds (1e-6) plus // milliseconds (1e-3) to seconds and nanoseconds (1e-9). @@ -90,14 +90,14 @@ bool Event::Wait(int cms) { #if HAVE_PTHREAD_COND_TIMEDWAIT_RELATIVE // Use relative time version, which tends to be more efficient for // pthread implementations where provided (like on Android). - ts.tv_sec = cms / 1000; - ts.tv_nsec = (cms % 1000) * 1000000; + ts.tv_sec = milliseconds / 1000; + ts.tv_nsec = (milliseconds % 1000) * 1000000; #else struct timeval tv; gettimeofday(&tv, NULL); - ts.tv_sec = tv.tv_sec + (cms / 1000); - ts.tv_nsec = tv.tv_usec * 1000 + (cms % 1000) * 1000000; + ts.tv_sec = tv.tv_sec + (milliseconds / 1000); + ts.tv_nsec = tv.tv_usec * 1000 + (milliseconds % 1000) * 1000000; // Handle overflow. if (ts.tv_nsec >= 1000000000) { diff --git a/webrtc/base/event.h b/webrtc/base/event.h index fb6868207..523715194 100644 --- a/webrtc/base/event.h +++ b/webrtc/base/event.h @@ -32,7 +32,10 @@ class Event { void Set(); void Reset(); - bool Wait(int cms); + + // Wait for the event to become signaled, for the specified number of + // |milliseconds|. To wait indefinetly, pass kForever. + bool Wait(int milliseconds); private: #if defined(WEBRTC_WIN)