FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
cefpython/src/include/base/cef_atomicops.h at cefpython54 · pythonthings/cefpython · GitHub
pythonthings
cefpython
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
cefpython
/
src
/
include
/
base
/
cef_atomicops.h
Copy path
More file actions
More file actions
Latest commit
History
History
History
200 lines (176 loc) · 8.88 KB
Breadcrumbs
cefpython
/
src
/
include
/
base
/
cef_atomicops.h
Copy path
File metadata and controls
200 lines (176 loc) · 8.88 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
//
Copyright (c) 2014 Marshall A. Greenblatt. Portions copyright (c) 2012
//
Google Inc. All rights reserved.
//
//
Redistribution and use in source and binary forms, with or without
//
modification, are permitted provided that the following conditions are
//
met:
//
//
* Redistributions of source code must retain the above copyright
//
notice, this list of conditions and the following disclaimer.
//
* Redistributions in binary form must reproduce the above
//
copyright notice, this list of conditions and the following disclaimer
//
in the documentation and/or other materials provided with the
//
distribution.
//
* Neither the name of Google Inc. nor the name Chromium Embedded
//
Framework nor the names of its contributors may be used to endorse
//
or promote products derived from this software without specific prior
//
written permission.
//
//
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
//
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
//
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
//
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
//
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
//
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
//
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
//
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
//
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
//
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
//
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
For atomic operations on reference counts, see cef_atomic_ref_count.h.
//
The routines exported by this module are subtle. If you use them, even if
//
you get the code right, it will depend on careful reasoning about atomicity
//
and memory ordering; it will be less readable, and harder to maintain. If
//
you plan to use these routines, you should have a good reason, such as solid
//
evidence that performance would otherwise suffer, or there being no
//
alternative. You should assume only properties explicitly guaranteed by the
//
specifications in this file. You are almost certainly _not_ writing code
//
just for the x86; if you assume x86 semantics, x86 hardware bugs and
//
implementations on other archtectures will cause your code to break. If you
//
do not know what you are doing, avoid these routines, and use a Mutex.
//
//
It is incorrect to make direct assignments to/from an atomic variable.
//
You should use one of the Load or Store routines. The NoBarrier
//
versions are provided when no barriers are needed:
//
NoBarrier_Store()
//
NoBarrier_Load()
//
Although there are currently no compiler enforcement, you are encouraged
//
to use these.
//
#
ifndef
CEF_INCLUDE_BASE_CEF_ATOMICOPS_H_
#
define
CEF_INCLUDE_BASE_CEF_ATOMICOPS_H_
#
pragma
once
#
if
defined(BASE_ATOMICOPS_H_)
//
Do nothing if the Chromium header has already been included.
//
This can happen in cases where Chromium code is used directly by the
//
client application. When using Chromium code directly always include
//
the Chromium header first to avoid type conflicts.
#
elif
defined(USING_CHROMIUM_INCLUDES)
//
When building CEF include the Chromium header directly.
#
include
"
base/atomicops.h
"
#
else
//
!USING_CHROMIUM_INCLUDES
//
The following is substantially similar to the Chromium implementation.
//
If the Chromium implementation diverges the below implementation should be
//
updated to match.
#
include
<
stdint.h
>
#
include
"
include/base/cef_build.h
"
#
if
defined(OS_WIN) && defined(ARCH_CPU_64_BITS)
//
windows.h #defines this (only on x64). This causes problems because the
//
public API also uses MemoryBarrier at the public name for this fence. So, on
//
X64, undef it, and call its documented
//
(http://msdn.microsoft.com/en-us/library/windows/desktop/ms684208.aspx)
//
implementation directly.
#
undef
MemoryBarrier
#
endif
namespace
base
{
namespace
subtle
{
typedef
int32_t
Atomic32;
#
ifdef
ARCH_CPU_64_BITS
//
We need to be able to go between Atomic64 and AtomicWord implicitly. This
//
means Atomic64 and AtomicWord should be the same type on 64-bit.
#
if
defined(__ILP32__) || defined(OS_NACL)
//
NaCl's intptr_t is not actually 64-bits on 64-bit!
//
http://code.google.com/p/nativeclient/issues/detail?id=1162
typedef
int64_t
Atomic64;
#
else
typedef
intptr_t
Atomic64;
#
endif
#
endif
//
Use AtomicWord for a machine-sized pointer. It will use the Atomic32 or
//
Atomic64 routines below, depending on your architecture.
typedef
intptr_t
AtomicWord;
//
Atomically execute:
//
result = *ptr;
//
if (*ptr == old_value)
//
*ptr = new_value;
//
return result;
//
//
I.e., replace "*ptr" with "new_value" if "*ptr" used to be "old_value".
//
Always return the old value of "*ptr"
//
//
This routine implies no memory barriers.
Atomic32
NoBarrier_CompareAndSwap
(
volatile
Atomic32* ptr,
Atomic32 old_value,
Atomic32 new_value);
//
Atomically store new_value into *ptr, returning the previous value held in
//
*ptr. This routine implies no memory barriers.
Atomic32
NoBarrier_AtomicExchange
(
volatile
Atomic32* ptr, Atomic32 new_value);
//
Atomically increment *ptr by "increment". Returns the new value of
//
*ptr with the increment applied. This routine implies no memory barriers.
Atomic32
NoBarrier_AtomicIncrement
(
volatile
Atomic32* ptr, Atomic32 increment);
Atomic32
Barrier_AtomicIncrement
(
volatile
Atomic32* ptr,
Atomic32 increment);
//
These following lower-level operations are typically useful only to people
//
implementing higher-level synchronization operations like spinlocks,
//
mutexes, and condition-variables. They combine CompareAndSwap(), a load, or
//
a store with appropriate memory-ordering instructions. "Acquire" operations
//
ensure that no later memory access can be reordered ahead of the operation.
//
"Release" operations ensure that no previous memory access can be reordered
//
after the operation. "Barrier" operations have both "Acquire" and "Release"
//
semantics. A MemoryBarrier() has "Barrier" semantics, but does no memory
//
access.
Atomic32
Acquire_CompareAndSwap
(
volatile
Atomic32* ptr,
Atomic32 old_value,
Atomic32 new_value);
Atomic32
Release_CompareAndSwap
(
volatile
Atomic32* ptr,
Atomic32 old_value,
Atomic32 new_value);
void
MemoryBarrier
();
void
NoBarrier_Store
(
volatile
Atomic32* ptr, Atomic32 value);
void
Acquire_Store
(
volatile
Atomic32* ptr, Atomic32 value);
void
Release_Store
(
volatile
Atomic32* ptr, Atomic32 value);
Atomic32
NoBarrier_Load
(
volatile
const
Atomic32* ptr);
Atomic32
Acquire_Load
(
volatile
const
Atomic32* ptr);
Atomic32
Release_Load
(
volatile
const
Atomic32* ptr);
//
64-bit atomic operations (only available on 64-bit processors).
#
ifdef
ARCH_CPU_64_BITS
Atomic64
NoBarrier_CompareAndSwap
(
volatile
Atomic64* ptr,
Atomic64 old_value,
Atomic64 new_value);
Atomic64
NoBarrier_AtomicExchange
(
volatile
Atomic64* ptr, Atomic64 new_value);
Atomic64
NoBarrier_AtomicIncrement
(
volatile
Atomic64* ptr, Atomic64 increment);
Atomic64
Barrier_AtomicIncrement
(
volatile
Atomic64* ptr, Atomic64 increment);
Atomic64
Acquire_CompareAndSwap
(
volatile
Atomic64* ptr,
Atomic64 old_value,
Atomic64 new_value);
Atomic64
Release_CompareAndSwap
(
volatile
Atomic64* ptr,
Atomic64 old_value,
Atomic64 new_value);
void
NoBarrier_Store
(
volatile
Atomic64* ptr, Atomic64 value);
void
Acquire_Store
(
volatile
Atomic64* ptr, Atomic64 value);
void
Release_Store
(
volatile
Atomic64* ptr, Atomic64 value);
Atomic64
NoBarrier_Load
(
volatile
const
Atomic64* ptr);
Atomic64
Acquire_Load
(
volatile
const
Atomic64* ptr);
Atomic64
Release_Load
(
volatile
const
Atomic64* ptr);
#
endif
//
ARCH_CPU_64_BITS
}
//
namespace subtle
}
//
namespace base
//
Include our platform specific implementation.
#
if
defined(OS_WIN) && defined(COMPILER_MSVC) && defined(ARCH_CPU_X86_FAMILY)
#
include
"
include/base/internal/cef_atomicops_x86_msvc.h
"
#
elif
defined(OS_MACOSX)
#
include
"
include/base/internal/cef_atomicops_mac.h
"
#
elif
defined(COMPILER_GCC) && defined(ARCH_CPU_X86_FAMILY)
#
include
"
include/base/internal/cef_atomicops_x86_gcc.h
"
#
elif
defined(COMPILER_GCC) && defined(__ARM_ARCH)
#
include
"
include/base/internal/cef_atomicops_arm_gcc.h
"
#
else
#
error
"Atomic operations are not supported on your platform"
#
endif
//
On some platforms we need additional declarations to make
//
AtomicWord compatible with our other Atomic* types.
#
if
defined(OS_MACOSX) || defined(OS_OPENBSD)
#
include
"
include/base/internal/cef_atomicops_atomicword_compat.h
"
#
endif
#
endif
//
!USING_CHROMIUM_INCLUDES
#
endif
//
CEF_INCLUDE_BASE_CEF_ATOMICOPS_H_
Back
|
FazBrowse Home
|
New Git URL