summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordarin@google.com <darin@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-08-09 08:28:45 +0000
committerdarin@google.com <darin@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-08-09 08:28:45 +0000
commit0e48e9dc55bd35d15db0476fbcf1c3529a5fa8de (patch)
tree1ba5674bef89d5a9a05538a8df4f878a9b8b893d
parent12ec562ec0236a94fcb7b376aab7d13b83a3de8a (diff)
downloadchromium_src-0e48e9dc55bd35d15db0476fbcf1c3529a5fa8de.zip
chromium_src-0e48e9dc55bd35d15db0476fbcf1c3529a5fa8de.tar.gz
chromium_src-0e48e9dc55bd35d15db0476fbcf1c3529a5fa8de.tar.bz2
rollback the experiments
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@630 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--base/object_watcher.cc43
1 files changed, 9 insertions, 34 deletions
diff --git a/base/object_watcher.cc b/base/object_watcher.cc
index bc5cdd2..9872a4c 100644
--- a/base/object_watcher.cc
+++ b/base/object_watcher.cc
@@ -29,26 +29,21 @@
#include "base/object_watcher.h"
-#include "base/histogram.h"
#include "base/logging.h"
namespace base {
-static int live_watches = 0;
-
//-----------------------------------------------------------------------------
-struct ObjectWatcher::Watch {
+struct ObjectWatcher::Watch : public Task {
ObjectWatcher* watcher; // The associated ObjectWatcher instance
HANDLE object; // The object being watched
HANDLE wait_object; // Returned by RegisterWaitForSingleObject
- HANDLE origin_thread;
+ MessageLoop* origin_loop; // Used to get back to the origin thread
Delegate* delegate; // Delegate to notify when signaled
bool did_signal; // DoneWaiting was called
- TimeTicks signal_time;
-
- void Run() {
+ virtual void Run() {
// The watcher may have already been torn down, in which case we need to
// just get out of dodge.
if (!watcher)
@@ -57,21 +52,8 @@ struct ObjectWatcher::Watch {
DCHECK(did_signal);
watcher->StopWatching();
- TimeDelta delta = TimeTicks::Now() - signal_time;
- HISTOGRAM_TIMES(L"ObjectWatcher_CallbackLatency", delta);
-
delegate->OnObjectSignaled(object);
}
-
- ~Watch() {
- CloseHandle(origin_thread);
- }
-
- static void CALLBACK ReturnToOriginThread(ULONG_PTR param) {
- Watch* self = reinterpret_cast<Watch*>(param);
- self->Run();
- delete self;
- }
};
//-----------------------------------------------------------------------------
@@ -92,12 +74,10 @@ bool ObjectWatcher::StartWatching(HANDLE object, Delegate* delegate) {
Watch* watch = new Watch;
watch->watcher = this;
watch->object = object;
+ watch->origin_loop = MessageLoop::current();
watch->delegate = delegate;
watch->did_signal = false;
- watch->origin_thread =
- OpenThread(THREAD_SET_CONTEXT, FALSE, GetCurrentThreadId());
-
// Since our job is to just notice when an object is signaled and report the
// result back to this thread, we can just run on a Windows wait thread.
DWORD wait_flags = WT_EXECUTEINWAITTHREAD | WT_EXECUTEONLYONCE;
@@ -111,9 +91,6 @@ bool ObjectWatcher::StartWatching(HANDLE object, Delegate* delegate) {
watch_ = watch;
- ++live_watches;
- HISTOGRAM_COUNTS(L"ObjectWatcher_LiveWatches", live_watches);
-
// 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);
@@ -124,10 +101,8 @@ bool ObjectWatcher::StopWatching() {
if (!watch_)
return false;
- --live_watches;
-
// Make sure ObjectWatcher is used in a single-threaded fashion.
- DCHECK(GetThreadId(watch_->origin_thread) == GetCurrentThreadId());
+ DCHECK(watch_->origin_loop == MessageLoop::current());
// If DoneWaiting is in progress, we wait for it to finish. We know whether
// DoneWaiting happened or not by inspecting the did_signal flag.
@@ -166,10 +141,10 @@ void CALLBACK ObjectWatcher::DoneWaiting(void* param, BOOLEAN timed_out) {
// Record that we ran this function.
watch->did_signal = true;
- watch->signal_time = TimeTicks::Now();
-
- QueueUserAPC(Watch::ReturnToOriginThread, watch->origin_thread,
- reinterpret_cast<ULONG_PTR>(watch));
+ // We rely on the locking in PostTask() to ensure that a memory barrier is
+ // provided, which in turn ensures our change to did_signal can be observed
+ // on the target thread.
+ watch->origin_loop->PostTask(FROM_HERE, watch);
}
void ObjectWatcher::WillDestroyCurrentMessageLoop() {