#include "spinlock.hpp"
◆ value_type
◆ spinlockbase() [1/3]
153 {
155#if QUICKCPPLIB_IN_THREAD_SANITIZER
156 v.store(0, memory_order_release);
157#endif
158 }
#define QUICKCPPLIB_ANNOTATE_RWLOCK_CREATE(p)
Definition config.hpp:102
atomic< T > v
Definition spinlock.hpp:143
◆ spinlockbase() [2/3]
◆ spinlockbase() [3/3]
Atomically move constructs.
166 {
168
169#if QUICKCPPLIB_IN_THREAD_SANITIZER
170 v.store(0, memory_order_release);
171#endif
172 }
◆ ~spinlockbase()
174 {
175#ifdef QUICKCPPLIB_ENABLE_VALGRIND
176 if(
v.load(memory_order_acquire))
177 {
179 }
180#endif
182 }
#define QUICKCPPLIB_ANNOTATE_RWLOCK_DESTROY(p)
Definition config.hpp:103
#define QUICKCPPLIB_ANNOTATE_RWLOCK_RELEASED(p, s)
Definition config.hpp:105
◆ operator=() [1/2]
◆ operator=() [2/2]
◆ load()
◆ store()
◆ try_lock() [1/3]
If atomic is zero, sets to 1 and returns true, else false.
191 {
192#if !QUICKCPPLIB_IN_THREAD_SANITIZER
193#ifdef QUICKCPPLIB_USE_VOLATILE_READ_FOR_AVOIDING_CMPXCHG
194
195 volatile T *_v = (
volatile T *) &
v;
196 if(*_v)
197 return false;
198#else
199 if(
v.load(memory_order_relaxed))
200 return false;
201#endif
202#endif
203#if 0
204
205
206 T ret =
v.exchange(1, memory_order_acquire);
207 if(!ret)
208#else
209 T expected = 0;
210 bool ret =
v.compare_exchange_weak(expected, 1, memory_order_acquire, memory_order_relaxed);
211 if(ret)
212#endif
213 {
215 return true;
216 }
217 else return false;
218 }
#define QUICKCPPLIB_ANNOTATE_RWLOCK_ACQUIRED(p, s)
Definition config.hpp:104
◆ try_lock() [2/3]
220 {
221 return v.load(memory_order_consume) ? false :
true;
222 }
◆ try_lock() [3/3]
If atomic equals expected, sets to 1 and returns true, else false with expected updated to actual value.
225 {
226 T t(0);
227#if !QUICKCPPLIB_IN_THREAD_SANITIZER
228#ifdef QUICKCPPLIB_USE_VOLATILE_READ_FOR_AVOIDING_CMPXCHG
229
230 volatile T *_v = (
volatile T *) &
v;
231 if((t = *_v))
232#else
233 t =
v.load(memory_order_relaxed);
234 if(t)
235#endif
236 {
237 expected = t;
238 return false;
239 }
240#endif
241 bool ret =
v.compare_exchange_weak(expected, 1, memory_order_acquire, memory_order_relaxed);
242 if(ret)
243 {
245 return true;
246 }
247 else
248 return false;
249 }
◆ unlock()
Sets the atomic to zero.
252 {
253
255 v.store(0, memory_order_release);
256 }
◆ int_yield()
The documentation for this struct was generated from the following file: