Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1268)

Unified Diff: base/atomic_flag.h

Issue 276002: Add AtomicFlag class to base/...... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | base/atomic_flag.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/atomic_flag.h
===================================================================
--- base/atomic_flag.h (revision 0)
+++ base/atomic_flag.h (revision 0)
@@ -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_
Property changes on: base/atomic_flag.h
___________________________________________________________________
Added: svn:eol-style
+ LF
« no previous file with comments | « no previous file | base/atomic_flag.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698