This source file includes following definitions.
- Get
- Acquire
- Release
- AssertAcquired
- DisableLocking
- DisableLockingOnThreadForTest
- EnableLockingOnThreadForTest
- CallWhileUnlocked
#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 {
base::LazyInstance<base::Lock>::Leaky g_proxy_lock = LAZY_INSTANCE_INITIALIZER;
bool g_disable_locking = false;
base::LazyInstance<base::ThreadLocalBoolean>::Leaky
g_disable_locking_for_thread = LAZY_INSTANCE_INITIALIZER;
base::LazyInstance<base::ThreadLocalBoolean>::Leaky g_proxy_locked_on_thread =
LAZY_INSTANCE_INITIALIZER;
base::Lock* ProxyLock::Get() {
if (g_disable_locking || g_disable_locking_for_thread.Get().Get())
return NULL;
return &g_proxy_lock.Get();
}
void ProxyLock::Acquire() {
base::Lock* lock = Get();
if (lock) {
const bool deadlock = g_proxy_locked_on_thread.Get().Get();
CHECK(!deadlock);
lock->Acquire();
g_proxy_locked_on_thread.Get().Set(true);
}
}
void ProxyLock::Release() {
base::Lock* lock = Get();
if (lock) {
const bool locked = g_proxy_locked_on_thread.Get().Get();
CHECK(locked);
g_proxy_locked_on_thread.Get().Set(false);
lock->Release();
}
}
void ProxyLock::AssertAcquired() {
base::Lock* lock = Get();
if (lock) {
const bool locked = g_proxy_locked_on_thread.Get().Get();
CHECK(locked);
lock->AssertAcquired();
}
}
void ProxyLock::DisableLocking() {
g_disable_locking = true;
}
void ProxyLock::DisableLockingOnThreadForTest() {
g_disable_locking_for_thread.Get().Set(true);
}
void ProxyLock::EnableLockingOnThreadForTest() {
g_disable_locking_for_thread.Get().Set(false);
}
void CallWhileUnlocked(const base::Closure& closure) {
ProxyAutoUnlock lock;
closure.Run();
}
}