diff options
author | darin@google.com <darin@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-08-05 23:16:41 +0000 |
---|---|---|
committer | darin@google.com <darin@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-08-05 23:16:41 +0000 |
commit | 2a1272586d0ab6719820ea25ac596683b33d0676 (patch) | |
tree | 3f0203f0cc289e067d9668d73265832e5ecf6742 /base/object_watcher.cc | |
parent | 836dff30efbff95f2090a024da25debe4edd2f83 (diff) | |
download | chromium_src-2a1272586d0ab6719820ea25ac596683b33d0676.zip chromium_src-2a1272586d0ab6719820ea25ac596683b33d0676.tar.gz chromium_src-2a1272586d0ab6719820ea25ac596683b33d0676.tar.bz2 |
ObjectWatcher needs to know when the current thread's MessageLoop is being destroyed. This might also be generically useful, so I added a new API on ML to observe when the ML is being destroyed. The notification is sent to observers just prior to ML::current() being modified to return NULL.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@407 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/object_watcher.cc')
-rw-r--r-- | base/object_watcher.cc | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/base/object_watcher.cc b/base/object_watcher.cc index 5e8c27b..9872a4c 100644 --- a/base/object_watcher.cc +++ b/base/object_watcher.cc @@ -29,7 +29,6 @@ #include "base/object_watcher.h" -#include "base/message_loop.h" #include "base/logging.h" namespace base { @@ -91,6 +90,10 @@ bool ObjectWatcher::StartWatching(HANDLE object, Delegate* delegate) { } watch_ = watch; + + // We need to know if the current message loop is going away so we can + // prevent the wait thread from trying to access a dead message loop. + MessageLoop::current()->AddDestructionObserver(this); return true; } @@ -124,6 +127,8 @@ bool ObjectWatcher::StopWatching() { delete watch_; watch_ = NULL; + + MessageLoop::current()->RemoveDestructionObserver(this); return true; } @@ -142,4 +147,10 @@ void CALLBACK ObjectWatcher::DoneWaiting(void* param, BOOLEAN timed_out) { watch->origin_loop->PostTask(FROM_HERE, watch); } +void ObjectWatcher::WillDestroyCurrentMessageLoop() { + // Need to shutdown the watch so that we don't try to access the MessageLoop + // after this point. + StopWatching(); +} + } // namespace base |