plibsys
patomic.h
Go to the documentation of this file.
1 /*
2  * The MIT License
3  *
4  * Copyright (C) 2010-2016 Alexander Saprykin <saprykin.spb@gmail.com>
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining
7  * a copy of this software and associated documentation files (the
8  * 'Software'), to deal in the Software without restriction, including
9  * without limitation the rights to use, copy, modify, merge, publish,
10  * distribute, sublicense, and/or sell copies of the Software, and to
11  * permit persons to whom the Software is furnished to do so, subject to
12  * the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be
15  * included in all copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
18  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24  */
25 
51 #if !defined (PLIBSYS_H_INSIDE) && !defined (PLIBSYS_COMPILATION)
52 # error "Header files shouldn't be included directly, consider using <plibsys.h> instead."
53 #endif
54 
55 #ifndef PLIBSYS_HEADER_PATOMIC_H
56 #define PLIBSYS_HEADER_PATOMIC_H
57 
58 #include <ptypes.h>
59 #include <pmacros.h>
60 
62 
72 P_LIB_API pint p_atomic_int_get (const volatile pint *atomic);
73 
83 P_LIB_API void p_atomic_int_set (volatile pint *atomic,
84  pint val);
85 
95 P_LIB_API void p_atomic_int_inc (volatile pint *atomic);
96 
110 
128  pint oldval,
129  pint newval);
130 
143 P_LIB_API pint p_atomic_int_add (volatile pint *atomic,
144  pint val);
145 
159 P_LIB_API puint p_atomic_int_and (volatile puint *atomic,
160  puint val);
161 
175 P_LIB_API puint p_atomic_int_or (volatile puint *atomic,
176  puint val);
177 
191 P_LIB_API puint p_atomic_int_xor (volatile puint *atomic,
192  puint val);
193 
202 P_LIB_API ppointer p_atomic_pointer_get (const volatile void *atomic);
203 
212 P_LIB_API void p_atomic_pointer_set (volatile void *atomic,
213  ppointer val);
214 
232  ppointer oldval,
233  ppointer newval);
234 
247 P_LIB_API pssize p_atomic_pointer_add (volatile void *atomic,
248  pssize val);
249 
263 P_LIB_API psize p_atomic_pointer_and (volatile void *atomic,
264  psize val);
265 
279 P_LIB_API psize p_atomic_pointer_or (volatile void *atomic,
280  psize val);
281 
295 P_LIB_API psize p_atomic_pointer_xor (volatile void *atomic,
296  psize val);
297 
307 
309 
310 #endif /* PLIBSYS_HEADER_PATOMIC_H */
P_LIB_API puint p_atomic_int_xor(volatile puint *atomic, puint val)
Atomically performs the bitwise &#39;xor&#39; operation of atomic value and val storing the result back in at...
#define P_END_DECLS
Closes .h file declarations to be exported as C functions, should be always used after P_BEGIN_DECLS...
Definition: pmacros.h:299
P_LIB_API ppointer p_atomic_pointer_get(const volatile void *atomic)
Gets ppointer-sized value from atomic.
P_LIB_API pboolean p_atomic_pointer_compare_and_exchange(volatile void *atomic, ppointer oldval, ppointer newval)
Compares oldval with the value pointed to by atomic and if they are equal, atomically exchanges the v...
P_LIB_API void p_atomic_pointer_set(volatile void *atomic, ppointer val)
Sets val to ppointer-sized atomic.
P_LIB_API void p_atomic_int_inc(volatile pint *atomic)
Increments pint value from atomic by 1.
int pint
Type for an int.
Definition: ptypes.h:120
P_LIB_API pboolean p_atomic_int_dec_and_test(volatile pint *atomic)
Decrements pint value from atomic by 1 and tests the result for zero.
P_LIB_API pboolean p_atomic_is_lock_free(void)
Checks whether atomic operations are lock-free.
P_LIB_API psize p_atomic_pointer_and(volatile void *atomic, psize val)
Atomically performs the bitwise &#39;and&#39; operation of ppointer-sized atomic value and val storing the re...
unsigned int psize
Type for a platform independent size_t.
Definition: ptypes.h:224
Miscellaneous macros.
void * ppointer
Type for a pointer.
Definition: ptypes.h:109
P_LIB_API psize p_atomic_pointer_or(volatile void *atomic, psize val)
Atomically performs the bitwise &#39;or&#39; operation of ppointer-sized atomic value and val storing the res...
signed int pboolean
Type for a bool.
Definition: ptypes.h:114
P_LIB_API pboolean p_atomic_int_compare_and_exchange(volatile pint *atomic, pint oldval, pint newval)
Compares oldval with the value pointed to by atomic and if they are equal, atomically exchanges the v...
P_LIB_API psize p_atomic_pointer_xor(volatile void *atomic, psize val)
Atomically performs the bitwise &#39;xor&#39; operation of ppointer-sized atomic value and val storing the re...
P_LIB_API pint p_atomic_int_add(volatile pint *atomic, pint val)
Atomically adds pint value to atomic value.
P_BEGIN_DECLS P_LIB_API pint p_atomic_int_get(const volatile pint *atomic)
Gets pint value from atomic.
#define P_LIB_API
Exports a symbol from a shared library.
Definition: pmacros.h:138
P_LIB_API puint p_atomic_int_or(volatile puint *atomic, puint val)
Atomically performs the bitwise &#39;or&#39; operation of atomic value and val storing the result back in ato...
unsigned int puint
Type for an unsigned int.
Definition: ptypes.h:129
Types definitions.
P_LIB_API pssize p_atomic_pointer_add(volatile void *atomic, pssize val)
Atomically adds ppointer-sized value to atomic value.
P_LIB_API puint p_atomic_int_and(volatile puint *atomic, puint val)
Atomically performs the bitwise &#39;and&#39; operation of atomic value and val storing the result back in at...
P_LIB_API void p_atomic_int_set(volatile pint *atomic, pint val)
Sets pint value to atomic.
signed int pssize
Type for a platform independent signed size_t.
Definition: ptypes.h:223
#define P_BEGIN_DECLS
Starts .h file declarations to be exported as C functions.
Definition: pmacros.h:298