Adaptive Framework  0.9.0
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
afw_atomic.h
Go to the documentation of this file.
1 // See the 'COPYING' file in the project root for licensing information.
2 /*
3  * Adaptive Framework Atomic Operation Header
4  *
5  * Copyright (c) 2010-2023 Clemson University
6  *
7  */
8 
9 #ifndef __AFW_ATOMIC_H__
10 #define __AFW_ATOMIC_H__
11 
12 #include "afw_interface.h"
13 
29 
37 AFW_DEFINE_STATIC_INLINE(afw_boolean_t)
39  AFW_ATOMIC afw_uint32_t *mem,
40  afw_uint32_t expected, afw_uint32_t desired)
41 {
42 #ifdef AFW_WINDOWS
43  LONG initial;
44  initial = InterlockedCompareExchange(mem, desired, expected);
45  return initial == expected;
46 #else
47  return atomic_compare_exchange_strong(mem, &expected, desired);
48 #endif
49 }
50 
51 
52 
60 AFW_DEFINE_STATIC_INLINE(afw_boolean_t)
62  AFW_ATOMIC afw_integer_t *mem,
63  afw_integer_t expected, afw_integer_t desired)
64 {
65 #ifdef AFW_WINDOWS
66  LONG64 initial;
67  initial = InterlockedCompareExchange64(mem, desired, expected);
68  return initial == expected;
69 #else
70  return atomic_compare_exchange_strong(mem, &expected, desired);
71 #endif
72 }
73 
74 
79 AFW_DEFINE_STATIC_INLINE(afw_uint32_t)
81  AFW_ATOMIC afw_uint32_t *mem)
82 {
83 #ifdef AFW_WINDOWS
84  return apr_atomic_dec32(mem);
85 #else
86  return --(*mem);
87 #endif
88 }
89 
90 
95 AFW_DEFINE_STATIC_INLINE(afw_integer_t)
97  AFW_ATOMIC afw_integer_t *mem)
98 {
99 #ifdef AFW_WINDOWS
100  return InterlockedDecrement64(mem);
101 #else
102  return --(*mem);
103 #endif
104 }
105 
106 
111 AFW_DEFINE_STATIC_INLINE(afw_uint32_t)
113  AFW_ATOMIC afw_uint32_t *mem)
114 {
115 #ifdef AFW_WINDOWS
116  return apr_atomic_inc32(mem);
117 #else
118  return ++(*mem);
119 #endif
120 }
121 
126 AFW_DEFINE_STATIC_INLINE(afw_integer_t)
128  AFW_ATOMIC afw_integer_t *mem)
129 {
130 #ifdef AFW_WINDOWS
131  return InterlockedIncrement64(mem);
132 #else
133  return ++(*mem);
134 #endif
135 }
136 
137 AFW_END_DECLARES
138 
141 #endif /* __AFW_ATOMIC_H__ */
#define AFW_BEGIN_DECLARES
Interfaceafw_interface header.
afw_integer_t afw_atomic_integer_decrement(AFW_ATOMIC afw_integer_t *mem)
Integer atomic decrement.
Definition: afw_atomic.h:96
afw_integer_t afw_atomic_integer_increment(AFW_ATOMIC afw_integer_t *mem)
Integer atomic increment.
Definition: afw_atomic.h:127
afw_uint32_t afw_atomic_uint32_increment(AFW_ATOMIC afw_uint32_t *mem)
32-bit atomic increment
Definition: afw_atomic.h:112
afw_boolean_t afw_atomic_integer_cas(AFW_ATOMIC afw_integer_t *mem, afw_integer_t expected, afw_integer_t desired)
Integer atomic decrement.
Definition: afw_atomic.h:61
afw_boolean_t afw_atomic_uint32_cas(AFW_ATOMIC afw_uint32_t *mem, afw_uint32_t expected, afw_uint32_t desired)
Integer atomic compare and swap.
Definition: afw_atomic.h:38
afw_uint32_t afw_atomic_uint32_decrement(AFW_ATOMIC afw_uint32_t *mem)
32-bit atomic decrement
Definition: afw_atomic.h:80
_Bool afw_boolean_t
Definition: afw_common.h:373
apr_uint32_t afw_uint32_t
32-bit unsigned integer.
Definition: afw_common.h:184
apr_int64_t afw_integer_t
typedef for big signed int.
Definition: afw_common.h:321