license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 1 | // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
2 | // Use of this source code is governed by a BSD-style license that can be | ||||
3 | // found in the LICENSE file. | ||||
[email protected] | 611dbe0 | 2008-08-05 09:57:36 | [diff] [blame] | 4 | |
5 | #ifndef BASE_ATOMIC_SEQUENCE_NUM_H_ | ||||
6 | #define BASE_ATOMIC_SEQUENCE_NUM_H_ | ||||
[email protected] | 32b76ef | 2010-07-26 23:08:24 | [diff] [blame] | 7 | #pragma once |
[email protected] | 611dbe0 | 2008-08-05 09:57:36 | [diff] [blame] | 8 | |
9 | #include "base/atomicops.h" | ||||
10 | #include "base/basictypes.h" | ||||
11 | |||||
12 | namespace base { | ||||
13 | |||||
14 | class AtomicSequenceNumber { | ||||
15 | public: | ||||
16 | AtomicSequenceNumber() : seq_(0) { } | ||||
[email protected] | a10a16b | 2008-09-02 13:11:46 | [diff] [blame] | 17 | explicit AtomicSequenceNumber(base::LinkerInitialized x) { /* seq_ is 0 */ } |
[email protected] | 611dbe0 | 2008-08-05 09:57:36 | [diff] [blame] | 18 | |
19 | int GetNext() { | ||||
20 | return static_cast<int>( | ||||
21 | base::subtle::NoBarrier_AtomicIncrement(&seq_, 1) - 1); | ||||
22 | } | ||||
23 | |||||
24 | private: | ||||
25 | base::subtle::Atomic32 seq_; | ||||
26 | DISALLOW_COPY_AND_ASSIGN(AtomicSequenceNumber); | ||||
27 | }; | ||||
28 | |||||
29 | } // namespace base | ||||
30 | |||||
31 | #endif // BASE_ATOMIC_SEQUENCE_NUM_H_ |