From 1c9cc40ac8ccaed63bda3770a16ed65ad2d0ee3c Mon Sep 17 00:00:00 2001 From: "timurrrr@chromium.org" Date: Fri, 16 Oct 2009 13:09:11 +0000 Subject: 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 --- base/atomic_flag.cc | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 base/atomic_flag.cc (limited to 'base/atomic_flag.cc') diff --git a/base/atomic_flag.cc b/base/atomic_flag.cc new file mode 100644 index 0000000..3e02543 --- /dev/null +++ b/base/atomic_flag.cc @@ -0,0 +1,28 @@ +// 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. + +#include "base/atomic_flag.h" + +#include "base/dynamic_annotations.h" +#include "base/logging.h" + +namespace base { + +void AtomicFlag::Set() { + DCHECK(!flag_); + // Set() method can't be called if the flag has already been set. + + ANNOTATE_HAPPENS_BEFORE(&flag_); + base::subtle::Release_Store(&flag_, 1); +} + +bool AtomicFlag::IsSet() const { + bool ret = base::subtle::Acquire_Load(&flag_) != 0; + if (ret) { + ANNOTATE_HAPPENS_AFTER(&flag_); + } + return ret; +} + +} // namespace base -- cgit v1.1