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

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

Issue 8016008: Make much of the proxy thread-safe with 1 great big lock. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merge Created 9 years, 2 months 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 | Annotate | Revision Log
« no previous file with comments | « ppapi/proxy/ppb_var_unittest.cc ('k') | ppapi/shared_impl/proxy_lock.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef PPAPI_SHARED_IMPL_PROXY_LOCK_H_
6 #define PPAPI_SHARED_IMPL_PROXY_LOCK_H_
7
8 #include "base/basictypes.h"
9
10 namespace base {
11 class Lock;
12 }
13
14 namespace ppapi {
15
16 // This is the one lock to rule them all for the ppapi proxy. All PPB interface
17 // functions that need to be synchronized should lock this lock on entry. This
18 // is normally accomplished by using an appropriate Enter RAII object at the
19 // beginning of each thunk function.
20 //
21 // TODO(dmichael): If this turns out to be too slow and contentious, we'll want
22 // to use multiple locks. E.g., one for the var tracker, one for the resource
23 // tracker, etc.
24 class ProxyLock {
25 public:
26 // Acquire the proxy lock. If it is currently held by another thread, block
27 // until it is available. If the lock has not been set using the 'Set' method,
28 // this operation does nothing. That is the normal case for the host side;
29 // see PluginResourceTracker for where the lock gets set for the out-of-
30 // process plugin case.
31 static void Acquire();
32 // Relinquish the proxy lock. If the lock has not been set, this does nothing.
33 static void Release();
34
35 // Set the lock that ProxyLock will use. The caller is responsible for
36 // ensuring that the lock stays valid so long as the ProxyLock may be in use.
37 static void Set(base::Lock* lock);
38 // Set the lock to NULL.
39 static void Reset();
40 private:
41 static base::Lock* lock_;
42
43 DISALLOW_IMPLICIT_CONSTRUCTORS(ProxyLock);
44 };
45
46 // A simple RAII class for locking the PPAPI proxy lock on entry and releasing
47 // on exit. This is for simple interfaces that don't use the 'thunk' system,
48 // such as PPB_Var and PPB_Core.
49 class ProxyAutoLock {
50 public:
51 ProxyAutoLock() {
52 ProxyLock::Acquire();
53 }
54 ~ProxyAutoLock() {
55 ProxyLock::Release();
56 }
57 private:
58 DISALLOW_COPY_AND_ASSIGN(ProxyAutoLock);
59 };
60
61 // The inverse of the above; unlock on construction, lock on destruction. This
62 // is useful for calling out to the plugin, when we need to unlock but ensure
63 // that we re-acquire the lock when the plugin is returns or raises an
64 // exception.
65 class ProxyAutoUnlock {
66 public:
67 ProxyAutoUnlock() {
68 ProxyLock::Release();
69 }
70 ~ProxyAutoUnlock() {
71 ProxyLock::Acquire();
72 }
73 private:
74 DISALLOW_COPY_AND_ASSIGN(ProxyAutoUnlock);
75 };
76
77
78 } // namespace ppapi
79
80 #endif // PPAPI_SHARED_IMPL_PROXY_LOCK_H_
OLDNEW
« no previous file with comments | « ppapi/proxy/ppb_var_unittest.cc ('k') | ppapi/shared_impl/proxy_lock.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698