| 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_SHARED_IMPL_PROXY_LOCK_H_ | 5 #ifndef PPAPI_SHARED_IMPL_PROXY_LOCK_H_ |
| 6 #define PPAPI_SHARED_IMPL_PROXY_LOCK_H_ | 6 #define PPAPI_SHARED_IMPL_PROXY_LOCK_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 template <class ReturnType, class P1, class P2, class P3, class P4, class P5> | 119 template <class ReturnType, class P1, class P2, class P3, class P4, class P5> |
| 120 ReturnType CallWhileUnlocked(ReturnType (*function)(P1, P2, P3, P4, P5), | 120 ReturnType CallWhileUnlocked(ReturnType (*function)(P1, P2, P3, P4, P5), |
| 121 const P1& p1, | 121 const P1& p1, |
| 122 const P2& p2, | 122 const P2& p2, |
| 123 const P3& p3, | 123 const P3& p3, |
| 124 const P4& p4, | 124 const P4& p4, |
| 125 const P5& p5) { | 125 const P5& p5) { |
| 126 ProxyAutoUnlock unlock; | 126 ProxyAutoUnlock unlock; |
| 127 return function(p1, p2, p3, p4, p5); | 127 return function(p1, p2, p3, p4, p5); |
| 128 } | 128 } |
| 129 void PPAPI_SHARED_EXPORT CallWhileUnlocked(const base::Closure& closure); |
| 129 | 130 |
| 130 // CallWhileLocked locks the ProxyLock and runs the given closure immediately. | 131 // CallWhileLocked locks the ProxyLock and runs the given closure immediately. |
| 131 // The lock is released when CallWhileLocked returns. This function assumes the | 132 // The lock is released when CallWhileLocked returns. This function assumes the |
| 132 // lock is not held. This is mostly for use in RunWhileLocked; see below. | 133 // lock is not held. This is mostly for use in RunWhileLocked; see below. |
| 133 void PPAPI_SHARED_EXPORT CallWhileLocked(const base::Closure& closure); | 134 void PPAPI_SHARED_EXPORT CallWhileLocked(const base::Closure& closure); |
| 134 | 135 |
| 135 // RunWhileLocked binds the given closure with CallWhileLocked and returns the | 136 // RunWhileLocked binds the given closure with CallWhileLocked and returns the |
| 136 // new Closure. This is for cases where you want to run a task, but you want to | 137 // new Closure. This is for cases where you want to run a task, but you want to |
| 137 // ensure that the ProxyLock is acquired for the duration of the task. | 138 // ensure that the ProxyLock is acquired for the duration of the task. |
| 138 // Example usage: | 139 // Example usage: |
| 139 // GetMainThreadMessageLoop()->PostDelayedTask( | 140 // GetMainThreadMessageLoop()->PostDelayedTask( |
| 140 // FROM_HERE, | 141 // FROM_HERE, |
| 141 // RunWhileLocked(base::Bind(&CallbackWrapper, callback, result)), | 142 // RunWhileLocked(base::Bind(&CallbackWrapper, callback, result)), |
| 142 // delay_in_ms); | 143 // delay_in_ms); |
| 143 inline base::Closure RunWhileLocked(const base::Closure& closure) { | 144 inline base::Closure RunWhileLocked(const base::Closure& closure) { |
| 144 return base::Bind(CallWhileLocked, closure); | 145 return base::Bind(CallWhileLocked, closure); |
| 145 } | 146 } |
| 146 | 147 |
| 147 } // namespace ppapi | 148 } // namespace ppapi |
| 148 | 149 |
| 149 #endif // PPAPI_SHARED_IMPL_PROXY_LOCK_H_ | 150 #endif // PPAPI_SHARED_IMPL_PROXY_LOCK_H_ |
| OLD | NEW |