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

Unified 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, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ppapi/shared_impl/proxy_lock.cc
diff --git a/ppapi/shared_impl/proxy_lock.cc b/ppapi/shared_impl/proxy_lock.cc
index 990130a19c6b127344875f256127c5b21481adcf..f9f937f2e2681753cff8ff2c253ab7bf5ede8c1e 100644
--- a/ppapi/shared_impl/proxy_lock.cc
+++ b/ppapi/shared_impl/proxy_lock.cc
@@ -4,30 +4,54 @@
#include "ppapi/shared_impl/proxy_lock.h"
+#include "base/lazy_instance.h"
#include "base/synchronization/lock.h"
+#include "base/threading/thread_local.h"
#include "ppapi/shared_impl/ppapi_globals.h"
namespace ppapi {
+// Simple single-thread deadlock detector for the proxy lock.
+// |true| when the current thread has the lock.
+base::LazyInstance<base::ThreadLocalBoolean>::Leaky
+ g_proxy_locked_on_thread = LAZY_INSTANCE_INITIALIZER;
+
// static
void ProxyLock::Acquire() {
base::Lock* lock(PpapiGlobals::Get()->GetProxyLock());
- if (lock)
+ if (lock) {
+ // This thread does not already hold the lock.
+ const bool deadlock = g_proxy_locked_on_thread.Get().Get();
+ CHECK(!deadlock);
+
lock->Acquire();
+ g_proxy_locked_on_thread.Get().Set(true);
+ }
}
// static
void ProxyLock::Release() {
base::Lock* lock(PpapiGlobals::Get()->GetProxyLock());
- if (lock)
+ if (lock) {
+ // This thread currently holds the lock.
+ const bool locked = g_proxy_locked_on_thread.Get().Get();
+ CHECK(locked);
+
+ g_proxy_locked_on_thread.Get().Set(false);
lock->Release();
+ }
}
// static
void ProxyLock::AssertAcquired() {
base::Lock* lock(PpapiGlobals::Get()->GetProxyLock());
- if (lock)
+ if (lock) {
+ // This thread currently holds the lock.
+ const bool locked = g_proxy_locked_on_thread.Get().Get();
+ CHECK(locked);
+
lock->AssertAcquired();
+ }
}
void CallWhileUnlocked(const base::Closure& closure) {
« 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