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

Unified Diff: base/memory/weak_ptr.h

Issue 7013059: Fix base::internal::WeakReferenceOwner races. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 7 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 | « no previous file | base/memory/weak_ptr.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/memory/weak_ptr.h
diff --git a/base/memory/weak_ptr.h b/base/memory/weak_ptr.h
index 0c6b4a70b46f3b06ef2bfab6b94cb7bc1b3da5e8..225c195d599d1e156dbef9616f076e02b6847e15 100644
--- a/base/memory/weak_ptr.h
+++ b/base/memory/weak_ptr.h
@@ -55,6 +55,7 @@
#include "base/base_api.h"
#include "base/logging.h"
#include "base/memory/ref_counted.h"
+#include "base/synchronization/lock.h"
#include "base/threading/thread_checker.h"
namespace base {
@@ -103,6 +104,7 @@ class BASE_API WeakReferenceOwner {
WeakReference GetRef() const;
bool HasRefs() const {
+ AutoLock auto_lock(lock_);
return flag_ != NULL;
}
@@ -110,10 +112,14 @@ class BASE_API WeakReferenceOwner {
// Indicates that this object will be used on another thread from now on.
void DetachFromThread() {
+ AutoLock auto_lock(lock_);
if (flag_) flag_->DetachFromThread();
}
private:
+ // Needs locking since WeakReference::Flag may be destroyed on a different
+ // thread.
+ mutable Lock lock_;
mutable WeakReference::Flag* flag_;
};
« no previous file with comments | « no previous file | base/memory/weak_ptr.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698