diff options
author | darin@google.com <darin@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-08-04 17:46:47 +0000 |
---|---|---|
committer | darin@google.com <darin@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-08-04 17:46:47 +0000 |
commit | b49054718ac2c49f629427c41a4ff2a6ba4bdb09 (patch) | |
tree | 0611d3d1d64574356dd3705ee66f7309a251bec3 /base/thread.cc | |
parent | 1c15248a5f6ffd48c99bca9d2fbd6d4b375e991c (diff) | |
download | chromium_src-b49054718ac2c49f629427c41a4ff2a6ba4bdb09.zip chromium_src-b49054718ac2c49f629427c41a4ff2a6ba4bdb09.tar.gz chromium_src-b49054718ac2c49f629427c41a4ff2a6ba4bdb09.tar.bz2 |
Revise the ObjectWatcher API to be one-to-one with the object being watched. This greatly simplifies the implementation and API.
Now consumers can use ObjectWatcher as a "smart pointer" class, which automatically cleans-up after itself when it goes out of scope.
I also switched away from the Task based API to one that is more compatible with MessageLoop::WatchObject. That allows me to make minimal changes to existing code, and it also means that consumers do not have to allocate Task objects to use this API.
In this CL, I included changes to make a couple consumers use ObjectWatcher instead of ML::WatchObject.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@322 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/thread.cc')
-rw-r--r-- | base/thread.cc | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/base/thread.cc b/base/thread.cc index cec558b..25379e1 100644 --- a/base/thread.cc +++ b/base/thread.cc @@ -33,10 +33,13 @@ #include "base/thread.h" #include "base/message_loop.h" +#include "base/object_watcher.h" #include "base/ref_counted.h" #include "base/string_util.h" #include "base/win_util.h" +namespace { + // This class is used when starting a thread. It passes information to the // thread function. It is referenced counted so we can cleanup the event // object used to synchronize thread startup properly. @@ -65,20 +68,15 @@ class ThreadQuitTask : public Task { }; // Once an object is signaled, quits the current inner message loop. -class QuitOnSignal : public MessageLoop::Watcher { +class QuitOnSignal : public base::ObjectWatcher::Delegate { public: - explicit QuitOnSignal(HANDLE signal) : signal_(signal) { - } virtual void OnObjectSignaled(HANDLE object) { - DCHECK_EQ(object, signal_); - MessageLoop::current()->WatchObject(signal_, NULL); MessageLoop::current()->Quit(); } - private: - HANDLE signal_; - DISALLOW_EVIL_CONSTRUCTORS(QuitOnSignal); }; +} // namespace + Thread::Thread(const char *name) : thread_(NULL), thread_id_(0), @@ -198,8 +196,10 @@ void Thread::InternalStop(bool run_message_loop) { message_loop_->PostTask(FROM_HERE, new ThreadQuitTask()); if (run_message_loop) { - QuitOnSignal signal_watcher(thread_); - MessageLoop::current()->WatchObject(thread_, &signal_watcher); + QuitOnSignal quit_on_signal; + base::ObjectWatcher signal_watcher; + CHECK(signal_watcher.StartWatching(thread_, &quit_on_signal)); + bool old_state = MessageLoop::current()->NestableTasksAllowed(); MessageLoop::current()->SetNestableTasksAllowed(true); MessageLoop::current()->Run(); |