diff options
author | darin@google.com <darin@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-08-11 14:35:15 +0000 |
---|---|---|
committer | darin@google.com <darin@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-08-11 14:35:15 +0000 |
commit | ffd830813ff2ad974e5b8596e7053cbfc77511f2 (patch) | |
tree | be43c75d0ca05361ed0905e8062fe5f62a583ae8 /base/thread.cc | |
parent | 7ce742d8a2434377005763f7b54e4ae844e3e2bd (diff) | |
download | chromium_src-ffd830813ff2ad974e5b8596e7053cbfc77511f2.zip chromium_src-ffd830813ff2ad974e5b8596e7053cbfc77511f2.tar.gz chromium_src-ffd830813ff2ad974e5b8596e7053cbfc77511f2.tar.bz2 |
Provide cross-platform implementation of WaitableEvent for use on Mac and Linux.
I gave the file the suffix _generic since it is implemented entirely in terms of other APIs in base.
This CL also adds a simple unit test for WaitableEvent, and I switched some code in thread.cc over to using WaitableEvent.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@648 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/thread.cc')
-rw-r--r-- | base/thread.cc | 15 |
1 files changed, 5 insertions, 10 deletions
diff --git a/base/thread.cc b/base/thread.cc index 0a19a16..ab79a9a 100644 --- a/base/thread.cc +++ b/base/thread.cc @@ -36,6 +36,7 @@ #include "base/object_watcher.h" #include "base/ref_counted.h" #include "base/string_util.h" +#include "base/waitable_event.h" #include "base/win_util.h" namespace { @@ -46,15 +47,9 @@ namespace { class ThreadStartInfo : public base::RefCountedThreadSafe<ThreadStartInfo> { public: Thread* self; - HANDLE start_event; + base::WaitableEvent start_event; - explicit ThreadStartInfo(Thread* t) - : self(t), - start_event(CreateEvent(NULL, FALSE, FALSE, NULL)) { - } - - ~ThreadStartInfo() { - CloseHandle(start_event); + explicit ThreadStartInfo(Thread* t) : self(t), start_event(false, false) { } }; @@ -170,7 +165,7 @@ bool Thread::StartWithStackSize(size_t stack_size) { } // Wait for the thread to start and initialize message_loop_ - WaitForSingleObject(info->start_event, INFINITE); + info->start_event.Wait(); return true; } @@ -232,7 +227,7 @@ unsigned __stdcall Thread::ThreadFunc(void* param) { self->message_loop_ = &message_loop; SetThreadName(self->thread_name().c_str(), GetCurrentThreadId()); message_loop.SetThreadName(self->thread_name()); - SetEvent(info->start_event); + info->start_event.Signal(); } // Let the thread do extra initialization. |