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 #ifndef PPAPI_THUNK_ENTER_H_ | 5 #ifndef PPAPI_THUNK_ENTER_H_ |
6 #define PPAPI_THUNK_ENTER_H_ | 6 #define PPAPI_THUNK_ENTER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 25 matching lines...) Expand all Loading... |
36 // input values are correct (the normal case), this should be set to true. In | 36 // input values are correct (the normal case), this should be set to true. In |
37 // some case like |IsFoo(PP_Resource)| the caller is questioning whether their | 37 // some case like |IsFoo(PP_Resource)| the caller is questioning whether their |
38 // handle is this type, and we don't want to report an error if it's not. | 38 // handle is this type, and we don't want to report an error if it's not. |
39 // | 39 // |
40 // Resource member functions: EnterResource | 40 // Resource member functions: EnterResource |
41 // Automatically interprets the given PP_Resource as a resource ID and sets | 41 // Automatically interprets the given PP_Resource as a resource ID and sets |
42 // up the resource object for you. | 42 // up the resource object for you. |
43 | 43 |
44 namespace subtle { | 44 namespace subtle { |
45 | 45 |
46 // Assert that we are holding the proxy lock. | |
47 PPAPI_THUNK_EXPORT void AssertLockHeld(); | |
48 | |
49 // This helps us define our RAII Enter classes easily. To make an RAII class | 46 // This helps us define our RAII Enter classes easily. To make an RAII class |
50 // which locks the proxy lock on construction and unlocks on destruction, | 47 // which locks the proxy lock on construction and unlocks on destruction, |
51 // inherit from |LockOnEntry<true>| before all other base classes. This ensures | 48 // inherit from |LockOnEntry<true>| before all other base classes. This ensures |
52 // that the lock is acquired before any other base class's constructor can run, | 49 // that the lock is acquired before any other base class's constructor can run, |
53 // and that the lock is only released after all other destructors have run. | 50 // and that the lock is only released after all other destructors have run. |
54 // (This order of initialization is guaranteed by C++98/C++11 12.6.2.10). | 51 // (This order of initialization is guaranteed by C++98/C++11 12.6.2.10). |
55 // | 52 // |
56 // For cases where you don't want to lock, inherit from |LockOnEntry<false>|. | 53 // For cases where you don't want to lock, inherit from |LockOnEntry<false>|. |
57 // This allows us to share more code between Enter* and Enter*NoLock classes. | 54 // This allows us to share more code between Enter* and Enter*NoLock classes. |
58 template <bool lock_on_entry> | 55 template <bool lock_on_entry> |
59 struct LockOnEntry; | 56 struct LockOnEntry; |
60 | 57 |
61 template <> | 58 template <> |
62 struct LockOnEntry<false> { | 59 struct LockOnEntry<false> { |
63 #if (!NDEBUG) | 60 #if (!NDEBUG) |
64 LockOnEntry() { | 61 LockOnEntry() { |
65 // You must already hold the lock to use Enter*NoLock. | 62 // You must already hold the lock to use Enter*NoLock. |
66 AssertLockHeld(); | 63 ProxyLock::AssertAcquired(); |
67 } | 64 } |
68 ~LockOnEntry() { | 65 ~LockOnEntry() { |
69 // You must not release the lock before leaving the scope of the | 66 // You must not release the lock before leaving the scope of the |
70 // Enter*NoLock. | 67 // Enter*NoLock. |
71 AssertLockHeld(); | 68 ProxyLock::AssertAcquired(); |
72 } | 69 } |
73 #endif | 70 #endif |
74 }; | 71 }; |
75 | 72 |
76 template <> | 73 template <> |
77 struct LockOnEntry<true> { | 74 struct LockOnEntry<true> { |
78 LockOnEntry() { | 75 LockOnEntry() { |
79 ppapi::ProxyLock::Acquire(); | 76 ppapi::ProxyLock::Acquire(); |
80 } | 77 } |
81 ~LockOnEntry() { | 78 ~LockOnEntry() { |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 ResourceCreationAPI* functions() { return functions_; } | 321 ResourceCreationAPI* functions() { return functions_; } |
325 | 322 |
326 private: | 323 private: |
327 ResourceCreationAPI* functions_; | 324 ResourceCreationAPI* functions_; |
328 }; | 325 }; |
329 | 326 |
330 } // namespace thunk | 327 } // namespace thunk |
331 } // namespace ppapi | 328 } // namespace ppapi |
332 | 329 |
333 #endif // PPAPI_THUNK_ENTER_H_ | 330 #endif // PPAPI_THUNK_ENTER_H_ |
OLD | NEW |