Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(377)

Side by Side Diff: ppapi/shared_impl/proxy_lock.cc

Issue 11280041: [ppapi] Simple deadlock detector for proxy lock. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Convert to a ThreadLocalBoolean. Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ppapi/shared_impl/proxy_lock.h" 5 #include "ppapi/shared_impl/proxy_lock.h"
6 6
7 #include "base/lazy_instance.h"
7 #include "base/synchronization/lock.h" 8 #include "base/synchronization/lock.h"
9 #include "base/threading/thread_local.h"
8 #include "ppapi/shared_impl/ppapi_globals.h" 10 #include "ppapi/shared_impl/ppapi_globals.h"
9 11
10 namespace ppapi { 12 namespace ppapi {
11 13
14 // Simple single-thread deadlock detector for the proxy lock.
15 // |true| when the current thread has the lock.
16 base::LazyInstance<base::ThreadLocalBoolean>::Leaky
17 g_proxy_locked_on_thread = LAZY_INSTANCE_INITIALIZER;
18
12 // static 19 // static
13 void ProxyLock::Acquire() { 20 void ProxyLock::Acquire() {
14 base::Lock* lock(PpapiGlobals::Get()->GetProxyLock()); 21 base::Lock* lock(PpapiGlobals::Get()->GetProxyLock());
15 if (lock) 22 if (lock) {
23 // This thread does not already hold the lock.
24 const bool deadlock = g_proxy_locked_on_thread.Get().Get();
25 CHECK(!deadlock);
26
16 lock->Acquire(); 27 lock->Acquire();
28 g_proxy_locked_on_thread.Get().Set(true);
29 }
17 } 30 }
18 31
19 // static 32 // static
20 void ProxyLock::Release() { 33 void ProxyLock::Release() {
21 base::Lock* lock(PpapiGlobals::Get()->GetProxyLock()); 34 base::Lock* lock(PpapiGlobals::Get()->GetProxyLock());
22 if (lock) 35 if (lock) {
36 // This thread currently holds the lock.
37 const bool locked = g_proxy_locked_on_thread.Get().Get();
38 CHECK(locked);
39
40 g_proxy_locked_on_thread.Get().Set(false);
23 lock->Release(); 41 lock->Release();
42 }
24 } 43 }
25 44
26 // static 45 // static
27 void ProxyLock::AssertAcquired() { 46 void ProxyLock::AssertAcquired() {
28 base::Lock* lock(PpapiGlobals::Get()->GetProxyLock()); 47 base::Lock* lock(PpapiGlobals::Get()->GetProxyLock());
29 if (lock) 48 if (lock) {
49 // This thread currently holds the lock.
50 const bool locked = g_proxy_locked_on_thread.Get().Get();
51 CHECK(locked);
52
30 lock->AssertAcquired(); 53 lock->AssertAcquired();
54 }
31 } 55 }
32 56
33 void CallWhileUnlocked(const base::Closure& closure) { 57 void CallWhileUnlocked(const base::Closure& closure) {
34 ProxyAutoUnlock lock; 58 ProxyAutoUnlock lock;
35 closure.Run(); 59 closure.Run();
36 } 60 }
37 61
38 void CallWhileLocked(const base::Closure& closure) { 62 void CallWhileLocked(const base::Closure& closure) {
39 ProxyAutoLock lock; 63 ProxyAutoLock lock;
40 closure.Run(); 64 closure.Run();
41 } 65 }
42 66
43 } // namespace ppapi 67 } // namespace ppapi
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698