3939#define CEF_INCLUDE_BASE_CEF_ATOMIC_REF_COUNT_H_
4040#pragma once
4141
42- #if defined(BASE_ATOMIC_REF_COUNT_H_)
43- // Do nothing if the Chromium header has already been included.
44- // This can happen in cases where Chromium code is used directly by the
45- // client application. When using Chromium code directly always include
46- // the Chromium header first to avoid type conflicts.
47- #elif defined(USING_CHROMIUM_INCLUDES)
42+ #if defined(USING_CHROMIUM_INCLUDES)
4843// When building CEF include the Chromium header directly.
4944#include " base/atomic_ref_count.h"
45+
46+ // Used when declaring a base::AtomicRefCount value. This is an object type with
47+ // Chromium headers.
48+ #define ATOMIC_DECLARATION (0 )
49+
50+ // Maintaining compatibility with AtompicRefCount* functions that were removed
51+ // from Chromium in http://crrev.com/ee96d561.
52+ namespace base {
53+
54+ // Increment a reference count by 1.
55+ inline void AtomicRefCountInc (volatile AtomicRefCount* ptr) {
56+ const_cast <AtomicRefCount*>(ptr)->Increment ();
57+ }
58+
59+ // Decrement a reference count by 1 and return whether the result is non-zero.
60+ // Insert barriers to ensure that state written before the reference count
61+ // became zero will be visible to a thread that has just made the count zero.
62+ inline bool AtomicRefCountDec (volatile AtomicRefCount* ptr) {
63+ return const_cast <AtomicRefCount*>(ptr)->Decrement ();
64+ }
65+
66+ // Return whether the reference count is one. If the reference count is used
67+ // in the conventional way, a refrerence count of 1 implies that the current
68+ // thread owns the reference and no other thread shares it. This call performs
69+ // the test for a reference count of one, and performs the memory barrier
70+ // needed for the owning thread to act on the object, knowing that it has
71+ // exclusive access to the object.
72+ inline bool AtomicRefCountIsOne (volatile AtomicRefCount* ptr) {
73+ return const_cast <AtomicRefCount*>(ptr)->IsOne ();
74+ }
75+
76+ // Return whether the reference count is zero. With conventional object
77+ // referencing counting, the object will be destroyed, so the reference count
78+ // should never be zero. Hence this is generally used for a debug check.
79+ inline bool AtomicRefCountIsZero (volatile AtomicRefCount* ptr) {
80+ return const_cast <AtomicRefCount*>(ptr)->IsZero ();
81+ }
82+
83+ } // namespace base
84+
5085#else // !USING_CHROMIUM_INCLUDES
5186// The following is substantially similar to the Chromium implementation.
5287// If the Chromium implementation diverges the below implementation should be
5691
5792// Annotations are not currently supported.
5893#define ANNOTATE_HAPPENS_BEFORE (obj ) /* empty */
59- #define ANNOTATE_HAPPENS_AFTER (obj ) /* empty */
94+ #define ANNOTATE_HAPPENS_AFTER (obj ) /* empty */
95+
96+ // Used when declaring a base::AtomicRefCount value. This is an integer/ptr type
97+ // with CEF headers.
98+ #define ATOMIC_DECLARATION = 0
6099
61100namespace base {
62101
63102typedef subtle::Atomic32 AtomicRefCount;
64103
65104// Increment a reference count by "increment", which must exceed 0.
66- inline void AtomicRefCountIncN (volatile AtomicRefCount * ptr,
105+ inline void AtomicRefCountIncN (volatile AtomicRefCount* ptr,
67106 AtomicRefCount increment) {
68107 subtle::NoBarrier_AtomicIncrement (ptr, increment);
69108}
@@ -72,7 +111,7 @@ inline void AtomicRefCountIncN(volatile AtomicRefCount *ptr,
72111// and return whether the result is non-zero.
73112// Insert barriers to ensure that state written before the reference count
74113// became zero will be visible to a thread that has just made the count zero.
75- inline bool AtomicRefCountDecN (volatile AtomicRefCount * ptr,
114+ inline bool AtomicRefCountDecN (volatile AtomicRefCount* ptr,
76115 AtomicRefCount decrement) {
77116 ANNOTATE_HAPPENS_BEFORE (ptr);
78117 bool res = (subtle::Barrier_AtomicIncrement (ptr, -decrement) != 0 );
@@ -83,14 +122,14 @@ inline bool AtomicRefCountDecN(volatile AtomicRefCount *ptr,
83122}
84123
85124// Increment a reference count by 1.
86- inline void AtomicRefCountInc (volatile AtomicRefCount * ptr) {
125+ inline void AtomicRefCountInc (volatile AtomicRefCount* ptr) {
87126 base::AtomicRefCountIncN (ptr, 1 );
88127}
89128
90129// Decrement a reference count by 1 and return whether the result is non-zero.
91130// Insert barriers to ensure that state written before the reference count
92131// became zero will be visible to a thread that has just made the count zero.
93- inline bool AtomicRefCountDec (volatile AtomicRefCount * ptr) {
132+ inline bool AtomicRefCountDec (volatile AtomicRefCount* ptr) {
94133 return base::AtomicRefCountDecN (ptr, 1 );
95134}
96135
@@ -100,7 +139,7 @@ inline bool AtomicRefCountDec(volatile AtomicRefCount *ptr) {
100139// the test for a reference count of one, and performs the memory barrier
101140// needed for the owning thread to act on the object, knowing that it has
102141// exclusive access to the object.
103- inline bool AtomicRefCountIsOne (volatile AtomicRefCount * ptr) {
142+ inline bool AtomicRefCountIsOne (volatile AtomicRefCount* ptr) {
104143 bool res = (subtle::Acquire_Load (ptr) == 1 );
105144 if (res) {
106145 ANNOTATE_HAPPENS_AFTER (ptr);
@@ -111,7 +150,7 @@ inline bool AtomicRefCountIsOne(volatile AtomicRefCount *ptr) {
111150// Return whether the reference count is zero. With conventional object
112151// referencing counting, the object will be destroyed, so the reference count
113152// should never be zero. Hence this is generally used for a debug check.
114- inline bool AtomicRefCountIsZero (volatile AtomicRefCount * ptr) {
153+ inline bool AtomicRefCountIsZero (volatile AtomicRefCount* ptr) {
115154 bool res = (subtle::Acquire_Load (ptr) == 0 );
116155 if (res) {
117156 ANNOTATE_HAPPENS_AFTER (ptr);
0 commit comments