Commit 59d5d59f authored by rvargas's avatar rvargas Committed by Commit bot

Use ScopedHandle for the private members of WaitableEvent.

BUG=416721
R=brettw@chromium.org

Review URL: https://codereview.chromium.org/593973002

Cr-Commit-Position: refs/heads/master@{#296258}
parent e2dcec51
......@@ -9,7 +9,7 @@
#include "base/basictypes.h"
#if defined(OS_WIN)
#include <windows.h>
#include "base/win/scoped_handle.h"
#endif
#if defined(OS_POSIX)
......@@ -53,6 +53,7 @@ class BASE_EXPORT WaitableEvent {
// Create a WaitableEvent from an Event HANDLE which has already been
// created. This objects takes ownership of the HANDLE and will close it when
// deleted.
// TODO(rvargas): Pass ScopedHandle instead (and on Release).
explicit WaitableEvent(HANDLE event_handle);
// Releases ownership of the handle from this object.
......@@ -90,7 +91,7 @@ class BASE_EXPORT WaitableEvent {
bool TimedWait(const TimeDelta& max_time);
#if defined(OS_WIN)
HANDLE handle() const { return handle_; }
HANDLE handle() const { return handle_.Get(); }
#endif
// Wait, synchronously, on multiple events.
......@@ -140,7 +141,7 @@ class BASE_EXPORT WaitableEvent {
friend class WaitableEventWatcher;
#if defined(OS_WIN)
HANDLE handle_;
win::ScopedHandle handle_;
#else
// On Windows, one can close a HANDLE which is currently being waited on. The
// MSDN documentation says that the resulting behaviour is 'undefined', but
......
......@@ -17,30 +17,27 @@ WaitableEvent::WaitableEvent(bool manual_reset, bool signaled)
: handle_(CreateEvent(NULL, manual_reset, signaled, NULL)) {
// We're probably going to crash anyways if this is ever NULL, so we might as
// well make our stack reports more informative by crashing here.
CHECK(handle_);
CHECK(handle_.IsValid());
}
WaitableEvent::WaitableEvent(HANDLE handle)
: handle_(handle) {
CHECK(handle) << "Tried to create WaitableEvent from NULL handle";
CHECK(handle_.IsValid()) << "Tried to create WaitableEvent from NULL handle";
}
WaitableEvent::~WaitableEvent() {
CloseHandle(handle_);
}
HANDLE WaitableEvent::Release() {
HANDLE rv = handle_;
handle_ = INVALID_HANDLE_VALUE;
return rv;
return handle_.Take();
}
void WaitableEvent::Reset() {
ResetEvent(handle_);
ResetEvent(handle_.Get());
}
void WaitableEvent::Signal() {
SetEvent(handle_);
SetEvent(handle_.Get());
}
bool WaitableEvent::IsSignaled() {
......@@ -49,7 +46,7 @@ bool WaitableEvent::IsSignaled() {
void WaitableEvent::Wait() {
base::ThreadRestrictions::AssertWaitAllowed();
DWORD result = WaitForSingleObject(handle_, INFINITE);
DWORD result = WaitForSingleObject(handle_.Get(), INFINITE);
// It is most unexpected that this should ever fail. Help consumers learn
// about it if it should ever fail.
DCHECK_EQ(WAIT_OBJECT_0, result) << "WaitForSingleObject failed";
......@@ -62,7 +59,8 @@ bool WaitableEvent::TimedWait(const TimeDelta& max_time) {
// is in milliseconds. If there are 5.5ms left, should the delay be 5 or 6?
// It should be 6 to avoid returning too early.
double timeout = ceil(max_time.InMillisecondsF());
DWORD result = WaitForSingleObject(handle_, static_cast<DWORD>(timeout));
DWORD result = WaitForSingleObject(handle_.Get(),
static_cast<DWORD>(timeout));
switch (result) {
case WAIT_OBJECT_0:
return true;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment