| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 BASE_TASK_H_ | 5 #ifndef BASE_TASK_H_ |
| 6 #define BASE_TASK_H_ | 6 #define BASE_TASK_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "base/non_thread_safe.h" | 9 #include "base/non_thread_safe.h" |
| 10 #include "base/raw_scoped_refptr_mismatch_checker.h" | 10 #include "base/raw_scoped_refptr_mismatch_checker.h" |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 // live longer than the RunnableMethod object, then a RunnableMethodTraits | 221 // live longer than the RunnableMethod object, then a RunnableMethodTraits |
| 222 // struct could be defined with empty RetainCallee and ReleaseCallee methods. | 222 // struct could be defined with empty RetainCallee and ReleaseCallee methods. |
| 223 // | 223 // |
| 224 // The DISABLE_RUNNABLE_METHOD_REFCOUNT macro is provided as a convenient way | 224 // The DISABLE_RUNNABLE_METHOD_REFCOUNT macro is provided as a convenient way |
| 225 // for declaring a RunnableMethodTraits that disables refcounting. | 225 // for declaring a RunnableMethodTraits that disables refcounting. |
| 226 | 226 |
| 227 template <class T> | 227 template <class T> |
| 228 struct RunnableMethodTraits { | 228 struct RunnableMethodTraits { |
| 229 RunnableMethodTraits() { | 229 RunnableMethodTraits() { |
| 230 #ifndef NDEBUG | 230 #ifndef NDEBUG |
| 231 origin_thread_id_ = PlatformThread::CurrentId(); | 231 origin_thread_id_ = base::PlatformThread::CurrentId(); |
| 232 #endif | 232 #endif |
| 233 } | 233 } |
| 234 | 234 |
| 235 ~RunnableMethodTraits() { | 235 ~RunnableMethodTraits() { |
| 236 #ifndef NDEBUG | 236 #ifndef NDEBUG |
| 237 // If destroyed on a separate thread, then we had better have been using | 237 // If destroyed on a separate thread, then we had better have been using |
| 238 // thread-safe reference counting! | 238 // thread-safe reference counting! |
| 239 if (origin_thread_id_ != PlatformThread::CurrentId()) | 239 if (origin_thread_id_ != base::PlatformThread::CurrentId()) |
| 240 DCHECK(T::ImplementsThreadSafeReferenceCounting()); | 240 DCHECK(T::ImplementsThreadSafeReferenceCounting()); |
| 241 #endif | 241 #endif |
| 242 } | 242 } |
| 243 | 243 |
| 244 void RetainCallee(T* obj) { | 244 void RetainCallee(T* obj) { |
| 245 #ifndef NDEBUG | 245 #ifndef NDEBUG |
| 246 // Catch NewRunnableMethod being called in an object's constructor. This | 246 // Catch NewRunnableMethod being called in an object's constructor. This |
| 247 // isn't safe since the method can be invoked before the constructor | 247 // isn't safe since the method can be invoked before the constructor |
| 248 // completes, causing the object to be deleted. | 248 // completes, causing the object to be deleted. |
| 249 obj->AddRef(); | 249 obj->AddRef(); |
| 250 obj->Release(); | 250 obj->Release(); |
| 251 #endif | 251 #endif |
| 252 obj->AddRef(); | 252 obj->AddRef(); |
| 253 } | 253 } |
| 254 | 254 |
| 255 void ReleaseCallee(T* obj) { | 255 void ReleaseCallee(T* obj) { |
| 256 obj->Release(); | 256 obj->Release(); |
| 257 } | 257 } |
| 258 | 258 |
| 259 private: | 259 private: |
| 260 #ifndef NDEBUG | 260 #ifndef NDEBUG |
| 261 PlatformThreadId origin_thread_id_; | 261 base::PlatformThreadId origin_thread_id_; |
| 262 #endif | 262 #endif |
| 263 }; | 263 }; |
| 264 | 264 |
| 265 // Convenience macro for declaring a RunnableMethodTraits that disables | 265 // Convenience macro for declaring a RunnableMethodTraits that disables |
| 266 // refcounting of a class. This is useful if you know that the callee | 266 // refcounting of a class. This is useful if you know that the callee |
| 267 // will outlive the RunnableMethod object and thus do not need the ref counts. | 267 // will outlive the RunnableMethod object and thus do not need the ref counts. |
| 268 // | 268 // |
| 269 // The invocation of DISABLE_RUNNABLE_METHOD_REFCOUNT should be done at the | 269 // The invocation of DISABLE_RUNNABLE_METHOD_REFCOUNT should be done at the |
| 270 // global namespace scope. Example: | 270 // global namespace scope. Example: |
| 271 // | 271 // |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 523 inline CancelableTask* NewRunnableFunction(Function function, | 523 inline CancelableTask* NewRunnableFunction(Function function, |
| 524 const A& a, const B& b, | 524 const A& a, const B& b, |
| 525 const C& c, const D& d, | 525 const C& c, const D& d, |
| 526 const E& e, const F& f, | 526 const E& e, const F& f, |
| 527 const G& g, const H& h) { | 527 const G& g, const H& h) { |
| 528 return new RunnableFunction<Function, Tuple8<A, B, C, D, E, F, G, H> >( | 528 return new RunnableFunction<Function, Tuple8<A, B, C, D, E, F, G, H> >( |
| 529 function, MakeTuple(a, b, c, d, e, f, g, h)); | 529 function, MakeTuple(a, b, c, d, e, f, g, h)); |
| 530 } | 530 } |
| 531 | 531 |
| 532 #endif // BASE_TASK_H_ | 532 #endif // BASE_TASK_H_ |
| OLD | NEW |