/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set ts=8 sts=2 et sw=2 tw=80: */ // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file.
class ObjectWatcher::Watch : public mozilla::Runnable { public:
ObjectWatcher* watcher; // The associated ObjectWatcher instance
HANDLE object; // The object being watched
HANDLE wait_object; // Returned by RegisterWaitForSingleObject
MessageLoop* origin_loop; // Used to get back to the origin thread
Delegate* delegate; // Delegate to notify when signaled bool did_signal; // DoneWaiting was called
NS_IMETHOD Run() override { // The watcher may have already been torn down, in which case we need to // just get out of dodge. if (!watcher) return NS_OK;
// 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_EXECUTEDEFAULT | WT_EXECUTEONLYONCE;
// 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); returntrue;
}
bool ObjectWatcher::StopWatching() { if (!watch_) returnfalse;
// Make sure ObjectWatcher is used in a single-threaded fashion.
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. if (!UnregisterWaitEx(watch_->wait_object, INVALID_HANDLE_VALUE)) {
NOTREACHED() << "UnregisterWaitEx failed: " << GetLastError(); returnfalse;
}
// Make sure that we see any mutation to did_signal. This should be a no-op // since we expect that UnregisterWaitEx resulted in a memory barrier, but // just to be sure, we're going to be explicit.
MemoryBarrier();
// If the watch has been posted, then we need to make sure it knows not to do // anything once it is run.
watch_->watcher = NULL;
// Record that we ran this function.
watch->did_signal = true;
// 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. if (watch->origin_loop->IsAcceptingTasks()) {
watch->origin_loop->PostTask(addrefedWatch.forget());
}
}
void ObjectWatcher::WillDestroyCurrentMessageLoop() { // Need to shutdown the watch so that we don't try to access the MessageLoop // after this point.
StopWatching();
}
} // namespace base
Messung V0.5
¤ Dauer der Verarbeitung: 0.1 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.