ipc/chromium/src/base/atomic_ref_count.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/ipc/chromium/src/base/atomic_ref_count.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,63 @@
     1.4 +// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
     1.5 +// Use of this source code is governed by a BSD-style license that can be
     1.6 +// found in the LICENSE file.
     1.7 +
     1.8 +// This is a low level implementation of atomic semantics for reference
     1.9 +// counting.  Please use base/ref_counted.h directly instead.
    1.10 +
    1.11 +#ifndef BASE_ATOMIC_REF_COUNT_H_
    1.12 +#define BASE_ATOMIC_REF_COUNT_H_
    1.13 +
    1.14 +#include "base/atomicops.h"
    1.15 +
    1.16 +namespace base {
    1.17 +
    1.18 +typedef subtle::Atomic32 AtomicRefCount;
    1.19 +
    1.20 +// Increment a reference count by "increment", which must exceed 0.
    1.21 +inline void AtomicRefCountIncN(volatile AtomicRefCount *ptr,
    1.22 +                               AtomicRefCount increment) {
    1.23 +  subtle::NoBarrier_AtomicIncrement(ptr, increment);
    1.24 +}
    1.25 +
    1.26 +// Decrement a reference count by "decrement", which must exceed 0,
    1.27 +// and return whether the result is non-zero.
    1.28 +// Insert barriers to ensure that state written before the reference count
    1.29 +// became zero will be visible to a thread that has just made the count zero.
    1.30 +inline bool AtomicRefCountDecN(volatile AtomicRefCount *ptr,
    1.31 +                               AtomicRefCount decrement) {
    1.32 +  return subtle::Barrier_AtomicIncrement(ptr, -decrement) != 0;
    1.33 +}
    1.34 +
    1.35 +// Increment a reference count by 1.
    1.36 +inline void AtomicRefCountInc(volatile AtomicRefCount *ptr) {
    1.37 +  base::AtomicRefCountIncN(ptr, 1);
    1.38 +}
    1.39 +
    1.40 +// Decrement a reference count by 1 and return whether the result is non-zero.
    1.41 +// Insert barriers to ensure that state written before the reference count
    1.42 +// became zero will be visible to a thread that has just made the count zero.
    1.43 +inline bool AtomicRefCountDec(volatile AtomicRefCount *ptr) {
    1.44 +  return base::AtomicRefCountDecN(ptr, 1);
    1.45 +}
    1.46 +
    1.47 +// Return whether the reference count is one.  If the reference count is used
    1.48 +// in the conventional way, a refrerence count of 1 implies that the current
    1.49 +// thread owns the reference and no other thread shares it.  This call performs
    1.50 +// the test for a reference count of one, and performs the memory barrier
    1.51 +// needed for the owning thread to act on the object, knowing that it has
    1.52 +// exclusive access to the object.
    1.53 +inline bool AtomicRefCountIsOne(volatile AtomicRefCount *ptr) {
    1.54 +  return subtle::Acquire_Load(ptr) == 1;
    1.55 +}
    1.56 +
    1.57 +// Return whether the reference count is zero.  With conventional object
    1.58 +// referencing counting, the object will be destroyed, so the reference count
    1.59 +// should never be zero.  Hence this is generally used for a debug check.
    1.60 +inline bool AtomicRefCountIsZero(volatile AtomicRefCount *ptr) {
    1.61 +  return subtle::Acquire_Load(ptr) == 0;
    1.62 +}
    1.63 +
    1.64 +}  // namespace base
    1.65 +
    1.66 +#endif  // BASE_ATOMIC_REF_COUNT_H_

mercurial