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

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

Issue 923263003: PPAPI: Make TrackedCallback more threadsafe (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Make RunWhileLocked not AssertAcquired Created 5 years, 8 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
« no previous file with comments | « ppapi/shared_impl/callback_tracker.cc ('k') | ppapi/shared_impl/tracked_callback.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 168
169 template <typename RunType> 169 template <typename RunType>
170 class RunWhileLockedHelper; 170 class RunWhileLockedHelper;
171 171
172 template <> 172 template <>
173 class RunWhileLockedHelper<void()> { 173 class RunWhileLockedHelper<void()> {
174 public: 174 public:
175 typedef base::Callback<void()> CallbackType; 175 typedef base::Callback<void()> CallbackType;
176 explicit RunWhileLockedHelper(const CallbackType& callback) 176 explicit RunWhileLockedHelper(const CallbackType& callback)
177 : callback_(new CallbackType(callback)) { 177 : callback_(new CallbackType(callback)) {
178 // Copying |callback| may adjust reference counts for bound Vars or
179 // Resources; we should have the lock already.
180 ProxyLock::AssertAcquired();
dmichael (off chromium) 2015/03/25 17:15:58 I needed to be able to use RunWhileLocked on the I
181 // CallWhileLocked and destruction might happen on a different thread from 178 // CallWhileLocked and destruction might happen on a different thread from
182 // creation. 179 // creation.
183 thread_checker_.DetachFromThread(); 180 thread_checker_.DetachFromThread();
184 } 181 }
185 void CallWhileLocked() { 182 void CallWhileLocked() {
186 // Bind thread_checker_ to this thread so we can check in the destructor. 183 // Bind thread_checker_ to this thread so we can check in the destructor.
187 DCHECK(thread_checker_.CalledOnValidThread()); 184 DCHECK(thread_checker_.CalledOnValidThread());
188 ProxyAutoLock lock; 185 ProxyAutoLock lock;
189 { 186 {
190 // Use a scope and local Callback to ensure that the callback is cleared 187 // Use a scope and local Callback to ensure that the callback is cleared
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 scoped_ptr<CallbackType> callback_; 258 scoped_ptr<CallbackType> callback_;
262 base::ThreadChecker thread_checker_; 259 base::ThreadChecker thread_checker_;
263 }; 260 };
264 261
265 template <typename P1, typename P2> 262 template <typename P1, typename P2>
266 class RunWhileLockedHelper<void(P1, P2)> { 263 class RunWhileLockedHelper<void(P1, P2)> {
267 public: 264 public:
268 typedef base::Callback<void(P1, P2)> CallbackType; 265 typedef base::Callback<void(P1, P2)> CallbackType;
269 explicit RunWhileLockedHelper(const CallbackType& callback) 266 explicit RunWhileLockedHelper(const CallbackType& callback)
270 : callback_(new CallbackType(callback)) { 267 : callback_(new CallbackType(callback)) {
271 ProxyLock::AssertAcquired();
272 thread_checker_.DetachFromThread(); 268 thread_checker_.DetachFromThread();
273 } 269 }
274 void CallWhileLocked(P1 p1, P2 p2) { 270 void CallWhileLocked(P1 p1, P2 p2) {
275 DCHECK(thread_checker_.CalledOnValidThread()); 271 DCHECK(thread_checker_.CalledOnValidThread());
276 ProxyAutoLock lock; 272 ProxyAutoLock lock;
277 { 273 {
278 scoped_ptr<CallbackType> temp_callback(callback_.Pass()); 274 scoped_ptr<CallbackType> temp_callback(callback_.Pass());
279 temp_callback->Run(p1, p2); 275 temp_callback->Run(p1, p2);
280 } 276 }
281 } 277 }
282 ~RunWhileLockedHelper() { 278 ~RunWhileLockedHelper() {
283 DCHECK(thread_checker_.CalledOnValidThread()); 279 DCHECK(thread_checker_.CalledOnValidThread());
284 if (callback_) { 280 if (callback_) {
285 ProxyAutoLock lock; 281 ProxyAutoLock lock;
286 callback_.reset(); 282 callback_.reset();
287 } 283 }
288 } 284 }
289 285
290 private: 286 private:
291 scoped_ptr<CallbackType> callback_; 287 scoped_ptr<CallbackType> callback_;
292 base::ThreadChecker thread_checker_; 288 base::ThreadChecker thread_checker_;
293 }; 289 };
294 290
295 template <typename P1, typename P2, typename P3> 291 template <typename P1, typename P2, typename P3>
296 class RunWhileLockedHelper<void(P1, P2, P3)> { 292 class RunWhileLockedHelper<void(P1, P2, P3)> {
297 public: 293 public:
298 typedef base::Callback<void(P1, P2, P3)> CallbackType; 294 typedef base::Callback<void(P1, P2, P3)> CallbackType;
299 explicit RunWhileLockedHelper(const CallbackType& callback) 295 explicit RunWhileLockedHelper(const CallbackType& callback)
300 : callback_(new CallbackType(callback)) { 296 : callback_(new CallbackType(callback)) {
301 ProxyLock::AssertAcquired();
302 thread_checker_.DetachFromThread(); 297 thread_checker_.DetachFromThread();
303 } 298 }
304 void CallWhileLocked(P1 p1, P2 p2, P3 p3) { 299 void CallWhileLocked(P1 p1, P2 p2, P3 p3) {
305 DCHECK(thread_checker_.CalledOnValidThread()); 300 DCHECK(thread_checker_.CalledOnValidThread());
306 ProxyAutoLock lock; 301 ProxyAutoLock lock;
307 { 302 {
308 scoped_ptr<CallbackType> temp_callback(callback_.Pass()); 303 scoped_ptr<CallbackType> temp_callback(callback_.Pass());
309 temp_callback->Run(p1, p2, p3); 304 temp_callback->Run(p1, p2, p3);
310 } 305 }
311 } 306 }
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 internal::RunWhileLockedHelper<FunctionType>* helper = 353 internal::RunWhileLockedHelper<FunctionType>* helper =
359 new internal::RunWhileLockedHelper<FunctionType>(callback); 354 new internal::RunWhileLockedHelper<FunctionType>(callback);
360 return base::Bind( 355 return base::Bind(
361 &internal::RunWhileLockedHelper<FunctionType>::CallWhileLocked, 356 &internal::RunWhileLockedHelper<FunctionType>::CallWhileLocked,
362 base::Owned(helper)); 357 base::Owned(helper));
363 } 358 }
364 359
365 } // namespace ppapi 360 } // namespace ppapi
366 361
367 #endif // PPAPI_SHARED_IMPL_PROXY_LOCK_H_ 362 #endif // PPAPI_SHARED_IMPL_PROXY_LOCK_H_
OLDNEW
« no previous file with comments | « ppapi/shared_impl/callback_tracker.cc ('k') | ppapi/shared_impl/tracked_callback.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698