summaryrefslogtreecommitdiffstats
path: root/base/atomic_flag.cc
blob: 3e025431a32f7cb514571818c7e50ab2c8e90aed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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