summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authorwillchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-11 19:55:43 +0000
committerwillchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-11 19:55:43 +0000
commit9ee7208282528778676429e7104ce004a1d1ea8c (patch)
tree1026ecb5a1b923db34a43b7af4f332563f2425e1 /base
parent8d856a8d6c62ac6493b4ff8db462433e1f6788a7 (diff)
downloadchromium_src-9ee7208282528778676429e7104ce004a1d1ea8c.zip
chromium_src-9ee7208282528778676429e7104ce004a1d1ea8c.tar.gz
chromium_src-9ee7208282528778676429e7104ce004a1d1ea8c.tar.bz2
Fix base::internal::WeakReference::Flag to be RefCountedThreadSafe.
This allows a base::WeakPtr to be deleted on a different thread, which will modify the refcount on Flag. BUG=none TEST=none Review URL: http://codereview.chromium.org/6826034 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@81142 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r--base/memory/weak_ptr.cc24
-rw-r--r--base/memory/weak_ptr.h23
2 files changed, 23 insertions, 24 deletions
diff --git a/base/memory/weak_ptr.cc b/base/memory/weak_ptr.cc
index fb09219..30c777c 100644
--- a/base/memory/weak_ptr.cc
+++ b/base/memory/weak_ptr.cc
@@ -10,31 +10,21 @@ namespace internal {
WeakReference::Flag::Flag(Flag** handle) : handle_(handle) {
}
-WeakReference::Flag::~Flag() {
- if (handle_)
- *handle_ = NULL;
-}
-
-void WeakReference::Flag::AddRef() const {
- DCHECK(CalledOnValidThread());
- RefCounted<Flag>::AddRef();
-}
-
-void WeakReference::Flag::Release() const {
- DCHECK(CalledOnValidThread());
- RefCounted<Flag>::Release();
-}
-
void WeakReference::Flag::Invalidate() {
- DCHECK(CalledOnValidThread());
+ DCHECK(thread_checker_.CalledOnValidThread());
handle_ = NULL;
}
bool WeakReference::Flag::IsValid() const {
- DCHECK(CalledOnValidThread());
+ DCHECK(thread_checker_.CalledOnValidThread());
return handle_ != NULL;
}
+WeakReference::Flag::~Flag() {
+ if (handle_)
+ *handle_ = NULL;
+}
+
WeakReference::WeakReference() {
}
diff --git a/base/memory/weak_ptr.h b/base/memory/weak_ptr.h
index edb9d93..0c6b4a7 100644
--- a/base/memory/weak_ptr.h
+++ b/base/memory/weak_ptr.h
@@ -55,7 +55,7 @@
#include "base/base_api.h"
#include "base/logging.h"
#include "base/memory/ref_counted.h"
-#include "base/threading/non_thread_safe.h"
+#include "base/threading/thread_checker.h"
namespace base {
@@ -65,19 +65,23 @@ namespace internal {
class BASE_API WeakReference {
public:
- class Flag : public RefCounted<Flag>, public base::NonThreadSafe {
+ // While Flag is bound to a specific thread, it may be deleted from another
+ // via base::WeakPtr::~WeakPtr().
+ class Flag : public RefCountedThreadSafe<Flag> {
public:
- Flag(Flag** handle);
- ~Flag();
+ explicit Flag(Flag** handle);
- void AddRef() const;
- void Release() const;
void Invalidate();
bool IsValid() const;
- void DetachFromThread() { base::NonThreadSafe::DetachFromThread(); }
+ void DetachFromThread() { thread_checker_.DetachFromThread(); }
private:
+ friend class base::RefCountedThreadSafe<Flag>;
+
+ ~Flag();
+
+ ThreadChecker thread_checker_;
Flag** handle_;
};
@@ -235,6 +239,11 @@ class WeakPtrFactory {
return weak_reference_owner_.HasRefs();
}
+ // Indicates that this object will be used on another thread from now on.
+ void DetachFromThread() {
+ weak_reference_owner_.DetachFromThread();
+ }
+
private:
internal::WeakReferenceOwner weak_reference_owner_;
T* ptr_;