summaryrefslogtreecommitdiffstats
path: root/base/waitable_event_watcher_posix.cc
diff options
context:
space:
mode:
authoragl@chromium.org <agl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-01-16 00:25:11 +0000
committeragl@chromium.org <agl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-01-16 00:25:11 +0000
commitcc2aa4193b5dbf3d4edeb4d3c33c94733c0b81d9 (patch)
tree24da027ee50590b54bae705e9566f92961a31b8a /base/waitable_event_watcher_posix.cc
parent075b9d39315fee5a08e7397d62db1441ee18e157 (diff)
downloadchromium_src-cc2aa4193b5dbf3d4edeb4d3c33c94733c0b81d9.zip
chromium_src-cc2aa4193b5dbf3d4edeb4d3c33c94733c0b81d9.tar.gz
chromium_src-cc2aa4193b5dbf3d4edeb4d3c33c94733c0b81d9.tar.bz2
Mac/Linux test fixes: hopefully this will fix some flakey tests
Review URL: http://codereview.chromium.org/18298 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@8143 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/waitable_event_watcher_posix.cc')
-rw-r--r--base/waitable_event_watcher_posix.cc30
1 files changed, 25 insertions, 5 deletions
diff --git a/base/waitable_event_watcher_posix.cc b/base/waitable_event_watcher_posix.cc
index e4e1a7f..10d47b7 100644
--- a/base/waitable_event_watcher_posix.cc
+++ b/base/waitable_event_watcher_posix.cc
@@ -80,6 +80,7 @@ class AsyncWaiter : public WaitableEvent::Waiter {
return tag == flag_.get();
}
+ private:
MessageLoop *const message_loop_;
Task *const cb_task_;
scoped_refptr<Flag> flag_;
@@ -101,12 +102,12 @@ class AsyncCallbackTask : public Task {
void Run() {
// Runs in MessageLoop thread.
- if (!flag_->value())
+ if (!flag_->value()) {
+ // This is to let the WaitableEventWatcher know that the event has occured
+ // because it needs to be able to return NULL from GetWatchedObject
+ flag_->Set();
delegate_->OnWaitableEventSignaled(event_);
-
- // This is to let the WaitableEventWatcher know that the event has occured
- // because it needs to be able to return NULL from GetWatchedEvent
- flag_->Set();
+ }
// We are deleted by the MessageLoop
}
@@ -138,6 +139,18 @@ bool WaitableEventWatcher::StartWatching
DCHECK(current_ml) << "Cannot create WaitableEventWatcher without a "
"current MessageLoop";
+ // A user may call StartWatching from within the callback function. In this
+ // case, we won't know that we have finished watching, expect that the Flag
+ // will have been set in AsyncCallbackTask::Run()
+ if (cancel_flag_.get() && cancel_flag_->value()) {
+ if (message_loop_) {
+ message_loop_->RemoveDestructionObserver(this);
+ message_loop_ = NULL;
+ }
+
+ cancel_flag_ = NULL;
+ }
+
DCHECK(!cancel_flag_.get()) << "StartWatching called while still watching";
cancel_flag_ = new Flag;
@@ -174,6 +187,13 @@ void WaitableEventWatcher::StopWatching() {
if (!cancel_flag_.get()) // if not currently watching...
return;
+ if (cancel_flag_->value()) {
+ // In this case, the event has fired, but we haven't figured that out yet.
+ // The WaitableEvent may have been deleted too.
+ cancel_flag_ = NULL;
+ return;
+ }
+
if (!event_) {
// We have no WaitableEvent. This means that we never enqueued a Waiter on
// an event because the event was already signaled when StartWatching was