summaryrefslogtreecommitdiffstats
path: root/base/atomic_ref_count.h
diff options
context:
space:
mode:
authordeanm@chromium.org <deanm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-26 11:28:03 +0000
committerdeanm@chromium.org <deanm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-26 11:28:03 +0000
commit001b694d745a07e3eb42d6f48e30b8f9f8901138 (patch)
tree4c000504c31b9c7a77d060a49f87537e18ba66a9 /base/atomic_ref_count.h
parent09e5f47ad0ab092bdf03025eb72c2a29cb9fe2ec (diff)
downloadchromium_src-001b694d745a07e3eb42d6f48e30b8f9f8901138.zip
chromium_src-001b694d745a07e3eb42d6f48e30b8f9f8901138.tar.gz
chromium_src-001b694d745a07e3eb42d6f48e30b8f9f8901138.tar.bz2
Added dynamic annotation files into base/.
Added annotations for atomic reference counting, LazyInstance and Singleton classes. This changelist is a part of an effort of adding ThreadSanitizer support for Chromium. See http://code.google.com/p/data-race-test/wiki/ThreadSanitizer Patch by Timur Iskhodzhanov. Review URL: http://codereview.chromium.org/147008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@19353 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/atomic_ref_count.h')
-rw-r--r--base/atomic_ref_count.h23
1 files changed, 20 insertions, 3 deletions
diff --git a/base/atomic_ref_count.h b/base/atomic_ref_count.h
index e3e1d17..73d7f43 100644
--- a/base/atomic_ref_count.h
+++ b/base/atomic_ref_count.h
@@ -4,11 +4,15 @@
// This is a low level implementation of atomic semantics for reference
// counting. Please use base/ref_counted.h directly instead.
+//
+// The implementation includes annotations to avoid some false positives
+// when using data race detection tools.
#ifndef BASE_ATOMIC_REF_COUNT_H_
#define BASE_ATOMIC_REF_COUNT_H_
#include "base/atomicops.h"
+#include "base/dynamic_annotations.h"
namespace base {
@@ -26,7 +30,12 @@ inline void AtomicRefCountIncN(volatile AtomicRefCount *ptr,
// became zero will be visible to a thread that has just made the count zero.
inline bool AtomicRefCountDecN(volatile AtomicRefCount *ptr,
AtomicRefCount decrement) {
- return subtle::Barrier_AtomicIncrement(ptr, -decrement) != 0;
+ ANNOTATE_HAPPENS_BEFORE(ptr);
+ bool res = (subtle::Barrier_AtomicIncrement(ptr, -decrement) != 0);
+ if (!res) {
+ ANNOTATE_HAPPENS_AFTER(ptr);
+ }
+ return res;
}
// Increment a reference count by 1.
@@ -48,14 +57,22 @@ inline bool AtomicRefCountDec(volatile AtomicRefCount *ptr) {
// needed for the owning thread to act on the object, knowing that it has
// exclusive access to the object.
inline bool AtomicRefCountIsOne(volatile AtomicRefCount *ptr) {
- return subtle::Acquire_Load(ptr) == 1;
+ bool res = (subtle::Acquire_Load(ptr) == 1);
+ if (res) {
+ ANNOTATE_HAPPENS_AFTER(ptr);
+ }
+ return res;
}
// Return whether the reference count is zero. With conventional object
// referencing counting, the object will be destroyed, so the reference count
// should never be zero. Hence this is generally used for a debug check.
inline bool AtomicRefCountIsZero(volatile AtomicRefCount *ptr) {
- return subtle::Acquire_Load(ptr) == 0;
+ bool res = (subtle::Acquire_Load(ptr) == 0);
+ if (res) {
+ ANNOTATE_HAPPENS_AFTER(ptr);
+ }
+ return res;
}
} // namespace base