OLD | NEW |
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/lazy_instance.h" |
8 #include "base/synchronization/lock.h" | 8 #include "base/synchronization/lock.h" |
9 #include "base/threading/thread_local.h" | 9 #include "base/threading/thread_local.h" |
10 #include "ppapi/shared_impl/ppapi_globals.h" | 10 #include "ppapi/shared_impl/ppapi_globals.h" |
11 | 11 |
12 namespace ppapi { | 12 namespace ppapi { |
13 | 13 |
14 base::LazyInstance<base::Lock>::Leaky | 14 base::LazyInstance<base::Lock>::Leaky g_proxy_lock = LAZY_INSTANCE_INITIALIZER; |
15 g_proxy_lock = LAZY_INSTANCE_INITIALIZER; | |
16 | 15 |
17 bool g_disable_locking = false; | 16 bool g_disable_locking = false; |
18 base::LazyInstance<base::ThreadLocalBoolean>::Leaky | 17 base::LazyInstance<base::ThreadLocalBoolean>::Leaky |
19 g_disable_locking_for_thread = LAZY_INSTANCE_INITIALIZER; | 18 g_disable_locking_for_thread = LAZY_INSTANCE_INITIALIZER; |
20 | 19 |
21 // Simple single-thread deadlock detector for the proxy lock. | 20 // Simple single-thread deadlock detector for the proxy lock. |
22 // |true| when the current thread has the lock. | 21 // |true| when the current thread has the lock. |
23 base::LazyInstance<base::ThreadLocalBoolean>::Leaky | 22 base::LazyInstance<base::ThreadLocalBoolean>::Leaky g_proxy_locked_on_thread = |
24 g_proxy_locked_on_thread = LAZY_INSTANCE_INITIALIZER; | 23 LAZY_INSTANCE_INITIALIZER; |
25 | 24 |
26 // static | 25 // static |
27 base::Lock* ProxyLock::Get() { | 26 base::Lock* ProxyLock::Get() { |
28 if (g_disable_locking || g_disable_locking_for_thread.Get().Get()) | 27 if (g_disable_locking || g_disable_locking_for_thread.Get().Get()) |
29 return NULL; | 28 return NULL; |
30 return &g_proxy_lock.Get(); | 29 return &g_proxy_lock.Get(); |
31 } | 30 } |
32 | 31 |
33 // Functions below should only access the lock via Get to ensure that they don't | 32 // Functions below should only access the lock via Get to ensure that they don't |
34 // try to use the lock on the host side of the proxy, where locking is | 33 // try to use the lock on the host side of the proxy, where locking is |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 void ProxyLock::EnableLockingOnThreadForTest() { | 90 void ProxyLock::EnableLockingOnThreadForTest() { |
92 g_disable_locking_for_thread.Get().Set(false); | 91 g_disable_locking_for_thread.Get().Set(false); |
93 } | 92 } |
94 | 93 |
95 void CallWhileUnlocked(const base::Closure& closure) { | 94 void CallWhileUnlocked(const base::Closure& closure) { |
96 ProxyAutoUnlock lock; | 95 ProxyAutoUnlock lock; |
97 closure.Run(); | 96 closure.Run(); |
98 } | 97 } |
99 | 98 |
100 } // namespace ppapi | 99 } // namespace ppapi |
OLD | NEW |