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

Side by Side Diff: base/task.h

Issue 399016: Fix race conditions where an object's constructor uses PostTask on itself. T... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 1 month 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
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 7
8 #include "base/non_thread_safe.h" 8 #include "base/non_thread_safe.h"
9 #include "base/tracked.h" 9 #include "base/tracked.h"
10 #include "base/tuple.h" 10 #include "base/tuple.h"
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 ~RunnableMethodTraits() { 214 ~RunnableMethodTraits() {
215 #ifndef NDEBUG 215 #ifndef NDEBUG
216 // If destroyed on a separate thread, then we had better have been using 216 // If destroyed on a separate thread, then we had better have been using
217 // thread-safe reference counting! 217 // thread-safe reference counting!
218 if (origin_thread_id_ != PlatformThread::CurrentId()) 218 if (origin_thread_id_ != PlatformThread::CurrentId())
219 DCHECK(T::ImplementsThreadSafeReferenceCounting()); 219 DCHECK(T::ImplementsThreadSafeReferenceCounting());
220 #endif 220 #endif
221 } 221 }
222 222
223 void RetainCallee(T* obj) { 223 void RetainCallee(T* obj) {
224 #ifndef NDEBUG
225 // Catch NewRunnableMethod being called in an object's constructor. This
226 // isn't safe since the method can be invoked before the constructor
227 // completes, causing the object to be deleted.
228 obj->AddRef();
229 obj->Release();
230 #endif
224 obj->AddRef(); 231 obj->AddRef();
225 } 232 }
226 233
227 void ReleaseCallee(T* obj) { 234 void ReleaseCallee(T* obj) {
228 obj->Release(); 235 obj->Release();
229 } 236 }
230 237
231 private: 238 private:
232 #ifndef NDEBUG 239 #ifndef NDEBUG
233 PlatformThreadId origin_thread_id_; 240 PlatformThreadId origin_thread_id_;
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after
668 675
669 template <class T, typename ReturnValue> 676 template <class T, typename ReturnValue>
670 typename CallbackWithReturnValue<ReturnValue>::Type* 677 typename CallbackWithReturnValue<ReturnValue>::Type*
671 NewCallbackWithReturnValue(T* object, ReturnValue (T::*method)()) { 678 NewCallbackWithReturnValue(T* object, ReturnValue (T::*method)()) {
672 return new CallbackWithReturnValueImpl<T, ReturnValue (T::*)(), ReturnValue>( 679 return new CallbackWithReturnValueImpl<T, ReturnValue (T::*)(), ReturnValue>(
673 object, method); 680 object, method);
674 } 681 }
675 682
676 683
677 #endif // BASE_TASK_H_ 684 #endif // BASE_TASK_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/crx_installer.h » ('j') | views/widget/aero_tooltip_manager.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698