Atomicity.h
1 /*
2  * Copyright (C) 2006-2007 by Marc Boris Duerner
3  * Copyright (C) 2010-2010 by Aloysius Indrayanto
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * As a special exception, you may use this file as part of a free
11  * software library without restriction. Specifically, if other files
12  * instantiate templates or use macros or inline functions from this
13  * file, or you compile this file and link it with other files to
14  * produce an executable, this file does not by itself cause the
15  * resulting executable to be covered by the GNU General Public
16  * License. This exception does not however invalidate any other
17  * reasons why the executable file might be covered by the GNU Library
18  * General Public License.
19  *
20  * This library is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23  * Lesser General Public License for more details.
24  *
25  * You should have received a copy of the GNU Lesser General Public
26  * License along with this library; if not, write to the Free Software
27  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
28  */
29 
30 #ifndef PT_ATOMICITY_H
31 #define PT_ATOMICITY_H
32 
33 #include <Pt/Api.h>
34 #include <Pt/Types.h>
35 
36 namespace Pt {
37 
51 union PT_API atomic_t
52 {
53  int i;
54  long l;
55  int32_t i32;
56  int64_t i64;
57  void* p;
58 #ifdef __cplusplus
59  explicit atomic_t(int v = 0);
60 #endif
61 };
62 
73 PT_API int atomicGet(volatile atomic_t& val);
74 
85 PT_API void atomicSet(volatile atomic_t& val, int n);
86 
95 PT_API int atomicIncrement(volatile atomic_t& val);
96 
105 PT_API int atomicDecrement(volatile atomic_t& val);
106 
115 PT_API int atomicExchange(volatile atomic_t& val, int exch);
116 
126 PT_API int atomicCompareExchange(volatile atomic_t& val, int exch, int comp);
127 
136 PT_API int atomicExchangeAdd(volatile atomic_t& val, int add);
137 
146 PT_API void* atomicExchange(void* volatile& val, void* exch);
147 
157 PT_API void* atomicCompareExchange(void* volatile& val, void* exch, void* comp);
158 
159 } // namespace Pt
160 
161 #endif
Core module.
Definition: Allocator.h:33
int atomicDecrement(volatile atomic_t &val)
Decreases a value by one as an atomic operation.
void * atomicExchange(void *volatile &val, void *exch)
Performs an atomic exchange operation.
int atomicExchangeAdd(volatile atomic_t &val, int add)
Performs atomic addition of two values.
int atomicGet(volatile atomic_t &val)
Atomically get a value.
int atomicExchange(volatile atomic_t &val, int exch)
Performs an atomic exchange operation.
int atomicCompareExchange(volatile atomic_t &val, int exch, int comp)
Performs an atomic compare-and-exchange operation.
int_type int32_t
Signed 32-bit integer type.
Definition: Api-Types.h:41
int atomicIncrement(volatile atomic_t &val)
Increases a value by one as an atomic operation.
void atomicSet(volatile atomic_t &val, int n)
Atomically set a value.
void * atomicCompareExchange(void *volatile &val, void *exch, void *comp)
Performs an atomic compare-and-exchange operation.
int_type int64_t
Signed 64-bit integer type.
Definition: Api-Types.h:55
Atomic integers to be used with atomicity functions.
Definition: Atomicity.h:52