diff options
author | deanm@chromium.org <deanm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-26 11:28:03 +0000 |
---|---|---|
committer | deanm@chromium.org <deanm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-26 11:28:03 +0000 |
commit | 001b694d745a07e3eb42d6f48e30b8f9f8901138 (patch) | |
tree | 4c000504c31b9c7a77d060a49f87537e18ba66a9 /base/singleton.h | |
parent | 09e5f47ad0ab092bdf03025eb72c2a29cb9fe2ec (diff) | |
download | chromium_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/singleton.h')
-rw-r--r-- | base/singleton.h | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/base/singleton.h b/base/singleton.h index 00cd448..afc2f0d 100644 --- a/base/singleton.h +++ b/base/singleton.h @@ -7,6 +7,7 @@ #include "base/at_exit.h" #include "base/atomicops.h" +#include "base/dynamic_annotations.h" #include "base/platform_thread.h" // Default traits for Singleton<Type>. Calls operator new and operator delete on @@ -116,8 +117,11 @@ class Singleton { static const base::subtle::AtomicWord kBeingCreatedMarker = 1; base::subtle::AtomicWord value = base::subtle::NoBarrier_Load(&instance_); - if (value != 0 && value != kBeingCreatedMarker) + if (value != 0 && value != kBeingCreatedMarker) { + // See the corresponding HAPPENS_BEFORE below. + ANNOTATE_HAPPENS_AFTER(&instance_); return reinterpret_cast<Type*>(value); + } // Object isn't created yet, maybe we will get to create it, let's try... if (base::subtle::Acquire_CompareAndSwap(&instance_, @@ -127,6 +131,11 @@ class Singleton { // will ever get here. Threads might be spinning on us, and they will // stop right after we do this store. Type* newval = Traits::New(); + + // This annotation helps race detectors recognize correct lock-less + // synchronization between different threads calling get(). + // See the corresponding HAPPENS_AFTER below and above. + ANNOTATE_HAPPENS_BEFORE(&instance_); base::subtle::Release_Store( &instance_, reinterpret_cast<base::subtle::AtomicWord>(newval)); @@ -150,6 +159,8 @@ class Singleton { PlatformThread::YieldCurrentThread(); } + // See the corresponding HAPPENS_BEFORE above. + ANNOTATE_HAPPENS_AFTER(&instance_); return reinterpret_cast<Type*>(value); } |