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

Unified Diff: base/task.h

Issue 251012: Assert that thread-safe reference counting is used with... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/ref_counted.h ('k') | chrome/browser/browser_process_impl.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/task.h
===================================================================
--- base/task.h (revision 27287)
+++ base/task.h (working copy)
@@ -205,12 +205,33 @@
template <class T>
struct RunnableMethodTraits {
- static void RetainCallee(T* obj) {
+ RunnableMethodTraits() {
+#ifndef NDEBUG
+ origin_thread_id_ = PlatformThread::CurrentId();
+#endif
+ }
+
+ ~RunnableMethodTraits() {
+#ifndef NDEBUG
+ // If destroyed on a separate thread, then we had better have been using
+ // thread-safe reference counting!
+ if (origin_thread_id_ != PlatformThread::CurrentId())
+ DCHECK(T::ImplementsThreadSafeReferenceCounting());
+#endif
+ }
+
+ void RetainCallee(T* obj) {
obj->AddRef();
}
- static void ReleaseCallee(T* obj) {
+
+ void ReleaseCallee(T* obj) {
obj->Release();
}
+
+ private:
+#ifndef NDEBUG
+ PlatformThreadId origin_thread_id_;
+#endif
};
// RunnableMethod and RunnableFunction -----------------------------------------
@@ -240,13 +261,13 @@
// RunnableMethod and NewRunnableMethod implementation -------------------------
template <class T, class Method, class Params>
-class RunnableMethod : public CancelableTask,
- public RunnableMethodTraits<T> {
+class RunnableMethod : public CancelableTask {
public:
RunnableMethod(T* obj, Method meth, const Params& params)
: obj_(obj), meth_(meth), params_(params) {
- RetainCallee(obj_);
+ traits_.RetainCallee(obj_);
}
+
~RunnableMethod() {
ReleaseCallee();
}
@@ -263,7 +284,7 @@
private:
void ReleaseCallee() {
if (obj_) {
- RunnableMethodTraits<T>::ReleaseCallee(obj_);
+ traits_.ReleaseCallee(obj_);
obj_ = NULL;
}
}
@@ -271,6 +292,7 @@
T* obj_;
Method meth_;
Params params_;
+ RunnableMethodTraits<T> traits_;
};
template <class T, class Method>
« no previous file with comments | « base/ref_counted.h ('k') | chrome/browser/browser_process_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698