diff options
author | timurrrr@chromium.org <timurrrr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-16 13:09:11 +0000 |
---|---|---|
committer | timurrrr@chromium.org <timurrrr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-16 13:09:11 +0000 |
commit | 1c9cc40ac8ccaed63bda3770a16ed65ad2d0ee3c (patch) | |
tree | 6ea0cb0c3a08ddec22b8470d62ded7d97b2da921 /base/atomic_flag.h | |
parent | 36b4f8050b8b5df172496236dccf5e9fa9814405 (diff) | |
download | chromium_src-1c9cc40ac8ccaed63bda3770a16ed65ad2d0ee3c.zip chromium_src-1c9cc40ac8ccaed63bda3770a16ed65ad2d0ee3c.tar.gz chromium_src-1c9cc40ac8ccaed63bda3770a16ed65ad2d0ee3c.tar.bz2 |
Add AtomicFlag class to base/...
This class is intended to replace wrong synchronization
via boolean like those in the bugs listed below.
TEST=./sconsbuild/Debug/base_unittests --gtest_filter="*AtomicFlag*"
BUG=21468,22520,24419
Review URL: http://codereview.chromium.org/276002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@29265 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/atomic_flag.h')
-rw-r--r-- | base/atomic_flag.h | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/base/atomic_flag.h b/base/atomic_flag.h new file mode 100644 index 0000000..ee33bf2 --- /dev/null +++ b/base/atomic_flag.h @@ -0,0 +1,37 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef BASE_ATOMIC_FLAG_H_ +#define BASE_ATOMIC_FLAG_H_ + +#include "base/atomicops.h" + +namespace base { + +// AtomicFlag allows threads to notify each other for a single occurrence +// of a single event. It maintains an abstract boolean "flag" that transitions +// to true at most once. It provides calls to query the boolean. +// +// Memory ordering: For any threads X and Y, if X calls Set(), then any +// action taken by X before it calls Set() is visible to thread Y after +// Y receives a true return value from IsSet(). +class AtomicFlag { + public: + // Sets "flag_" to "initial_value". + explicit AtomicFlag(bool initial_value = false) + : flag_(initial_value ? 1 : 0) { } + ~AtomicFlag() {} + + void Set(); // Set "flag_" to true. May be called only once. + bool IsSet() const; // Return "flag_". + + private: + base::subtle::Atomic32 flag_; + + DISALLOW_COPY_AND_ASSIGN(AtomicFlag); +}; + +} // namespace base + +#endif // BASE_ATOMIC_FLAG_H_ |