security/sandbox/chromium/base/atomic_sequence_num.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 // Copyright (c) 2012 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.
     5 #ifndef BASE_ATOMIC_SEQUENCE_NUM_H_
     6 #define BASE_ATOMIC_SEQUENCE_NUM_H_
     8 #include "base/atomicops.h"
     9 #include "base/basictypes.h"
    11 namespace base {
    13 class AtomicSequenceNumber;
    15 // Static (POD) AtomicSequenceNumber that MUST be used in global scope (or
    16 // non-function scope) ONLY. This implementation does not generate any static
    17 // initializer.  Note that it does not implement any constructor which means
    18 // that its fields are not initialized except when it is stored in the global
    19 // data section (.data in ELF). If you want to allocate an atomic sequence
    20 // number on the stack (or heap), please use the AtomicSequenceNumber class
    21 // declared below.
    22 class StaticAtomicSequenceNumber {
    23  public:
    24   inline int GetNext() {
    25     return static_cast<int>(
    26         base::subtle::NoBarrier_AtomicIncrement(&seq_, 1) - 1);
    27   }
    29  private:
    30   friend class AtomicSequenceNumber;
    32   inline void Reset() {
    33     base::subtle::Release_Store(&seq_, 0);
    34   }
    36   base::subtle::Atomic32 seq_;
    37 };
    39 // AtomicSequenceNumber that can be stored and used safely (i.e. its fields are
    40 // always initialized as opposed to StaticAtomicSequenceNumber declared above).
    41 // Please use StaticAtomicSequenceNumber if you want to declare an atomic
    42 // sequence number in the global scope.
    43 class AtomicSequenceNumber {
    44  public:
    45   AtomicSequenceNumber() {
    46     seq_.Reset();
    47   }
    49   inline int GetNext() {
    50     return seq_.GetNext();
    51   }
    53  private:
    54   StaticAtomicSequenceNumber seq_;
    55   DISALLOW_COPY_AND_ASSIGN(AtomicSequenceNumber);
    56 };
    58 }  // namespace base
    60 #endif  // BASE_ATOMIC_SEQUENCE_NUM_H_

mercurial