diff options
author | darin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-30 04:29:20 +0000 |
---|---|---|
committer | darin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-30 04:29:20 +0000 |
commit | 39fe32a42c9eab376aeefd1ae845085d8828c3ec (patch) | |
tree | a183411c44c9c958fd2f4ce05138c316158b94a1 /base | |
parent | 5924fb63dc581087092336c3449e80a24d848492 (diff) | |
download | chromium_src-39fe32a42c9eab376aeefd1ae845085d8828c3ec.zip chromium_src-39fe32a42c9eab376aeefd1ae845085d8828c3ec.tar.gz chromium_src-39fe32a42c9eab376aeefd1ae845085d8828c3ec.tar.bz2 |
Reverting 27389.
Review URL: http://codereview.chromium.org/246027
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@27594 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r-- | base/message_pump_glib_unittest.cc | 4 | ||||
-rw-r--r-- | base/ref_counted.h | 4 | ||||
-rw-r--r-- | base/task.h | 34 |
3 files changed, 34 insertions, 8 deletions
diff --git a/base/message_pump_glib_unittest.cc b/base/message_pump_glib_unittest.cc index e0ad260..e3a04e8 100644 --- a/base/message_pump_glib_unittest.cc +++ b/base/message_pump_glib_unittest.cc @@ -185,8 +185,8 @@ class MessagePumpGLibTest : public testing::Test { // This lets us call NewRunnableMethod on EventInjector instances. template<> struct RunnableMethodTraits<EventInjector> { - static void RetainCallee(EventInjector* obj) { } - static void ReleaseCallee(EventInjector* obj) { } + void RetainCallee(EventInjector* obj) { } + void ReleaseCallee(EventInjector* obj) { } }; TEST_F(MessagePumpGLibTest, TestQuit) { diff --git a/base/ref_counted.h b/base/ref_counted.h index 097d16e..70536b9 100644 --- a/base/ref_counted.h +++ b/base/ref_counted.h @@ -14,6 +14,8 @@ namespace subtle { class RefCountedBase { public: + static bool ImplementsThreadSafeReferenceCounting() { return false; } + bool HasOneRef() const { return ref_count_ == 1; } protected: @@ -38,6 +40,8 @@ class RefCountedBase { class RefCountedThreadSafeBase { public: + static bool ImplementsThreadSafeReferenceCounting() { return true; } + bool HasOneRef() const; protected: diff --git a/base/task.h b/base/task.h index c827681..e9da8b3 100644 --- a/base/task.h +++ b/base/task.h @@ -205,12 +205,33 @@ class ReleaseTask : public CancelableTask { 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 @@ struct RunnableMethodTraits { // 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 @@ class RunnableMethod : public CancelableTask, private: void ReleaseCallee() { if (obj_) { - RunnableMethodTraits<T>::ReleaseCallee(obj_); + traits_.ReleaseCallee(obj_); obj_ = NULL; } } @@ -271,6 +292,7 @@ class RunnableMethod : public CancelableTask, T* obj_; Method meth_; Params params_; + RunnableMethodTraits<T> traits_; }; template <class T, class Method> |