From 2a59a9065e6cbb949162964f75e962ad3a2349d7 Mon Sep 17 00:00:00 2001 From: "cpu@chromium.org" Date: Tue, 30 Apr 2013 08:54:17 +0000 Subject: Adding TryPostTask to the message loop This is to allow code in certain high priority threads to use the task/message loop facility. For example the audio threads that currently use sentinel booleans and recurring timers. TryPostTask will fail if it is going contend for the lock. The caller must handle that case. Note that the current tests do not test the contended mode. I don't see a way to test that case without introducing runtime penalty for all of chrome. BUG=none TEST=included Review URL: https://chromiumcodereview.appspot.com/14387002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@197315 0039d316-1c4b-4281-b951-d872f2087c98 --- base/synchronization/lock.h | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'base/synchronization') diff --git a/base/synchronization/lock.h b/base/synchronization/lock.h index bec37fb..7e8ffe7 100644 --- a/base/synchronization/lock.h +++ b/base/synchronization/lock.h @@ -96,10 +96,16 @@ class BASE_EXPORT Lock { // A helper class that acquires the given Lock while the AutoLock is in scope. class AutoLock { public: + struct AlreadyAcquired {}; + explicit AutoLock(Lock& lock) : lock_(lock) { lock_.Acquire(); } + AutoLock(Lock& lock, const AlreadyAcquired&) : lock_(lock) { + lock_.AssertAcquired(); + } + ~AutoLock() { lock_.AssertAcquired(); lock_.Release(); -- cgit v1.1