Zen API

- Home
- Help Topics
- Types by Category
- All Types
- Files

All Classes Files Functions Variables Typedefs Macros Groups Pages
kAtomic.h
Go to the documentation of this file.
1 /**
2 * @file kAtomic.h
3 * @brief Declares the kAtomic class.
4 *
5 * @internal
6 * Copyright (C) 2012-2014 by LMI Technologies Inc.
7 * Licensed under the MIT License.
8 * Redistributed files must retain the above copyright notice.
9 */
10 #include <kApi/kApiDef.h> //--inclusion order controlled by kApiDef
11
12 #ifndef K_API_ATOMIC_H
13 #define K_API_ATOMIC_H
14
15 kBeginHeader()
16
17 /**
18 * @class kAtomic
19 * @ingroup kApi-Threads
20 * @brief Collection of functions for atomic variable operations.
21 */
22
23 /**
24 * Increments an atomic variable.
25 *
26 * This method is thread-safe. Implements a full memory barrier.
27 *
28 * @public @memberof kAtomic
29 * @param atomic Pointer to atomic variable.
30 * @return New atomic value.
31 */
32 kFx(k32s) kAtomic_Increment32s(volatile k32s* atomic);
33
34 /**
35 * Decrements an atomic variable.
36 *
37 * This method is thread-safe. Implements a full memory barrier.
38 *
39 * @public @memberof kAtomic
40 * @param atomic Pointer to atomic variable.
41 * @return New atomic value.
42 */
43 kFx(k32s) kAtomic_Decrement32s(volatile k32s* atomic);
44
45 /**
46 * Exchanges the value of an atomic variable.
47 *
48 * This method is thread-safe. Implements a full memory barrier.
49 *
50 * @public @memberof kAtomic
51 * @param atomic Pointer to atomic variable.
52 * @param value New atomic value.
53 * @return Previous atomic value.
54 */
55 kFx(k32s) kAtomic_Exchange32s(volatile k32s* atomic, k32s value);
56
57 /**
58 * Conditionally exchanges the value of an atomic variable.
59 *
60 * If the atomic value is equal to the oldValue argument, then it is replaced by the value argument.
61 *
62 * This method is thread-safe. Implements a full memory barrier.
63 *
64 * @public @memberof kAtomic
65 * @param atomic Pointer to atomic variable.
66 * @param oldValue Previous atomic value.
67 * @param value New atomic value.
68 * @return kTRUE if the exchange succeeded.
69 */
70 kFx(kBool) kAtomic_CompareExchange32s(volatile k32s* atomic, k32s oldValue, k32s value);
71
72 /**
73 * Gets the current value of an atomic variable.
74 *
75 * This method is thread-safe. Implements a full memory barrier.
76 *
77 * @public @memberof kAtomic
78 * @param atomic Pointer to atomic variable.
79 * @return Atomic value.
80 */
81 kFx(k32s) kAtomic_Get32s(volatile k32s* atomic);
82
83 /**
84 * Exchanges the value of an atomic variable.
85 *
86 * This method is thread-safe. Implements a full memory barrier.
87 *
88 * @public @memberof kAtomic
89 * @param atomic Pointer to atomic variable.
90 * @param value New atomic value.
91 * @return Previous atomic value.
92 */
93 kFx(kPointer) kAtomic_ExchangePointer(volatile kPointer* atomic, kPointer value);
94
95 /**
96 * Conditionally exchanges the value of an atomic variable.
97 *
98 * If the atomic value is equal to the oldValue argument, then it is replaced by the value argument.
99 *
100 * This method is thread-safe. Implements a full memory barrier.
101 *
102 * @public @memberof kAtomic
103 * @param atomic Pointer to atomic variable.
104 * @param oldValue Previous atomic value.
105 * @param value New atomic value.
106 * @return Previous atomic value.
107 */
108 kFx(kBool) kAtomic_CompareExchangePointer(volatile kPointer* atomic, kPointer oldValue, kPointer value);
109
110 #define kAtomic_Increment32s_(ATM) kxAtomic_Increment32s_(ATM) ///< Macro version of kAtomic_Increment32s.
111 #define kAtomic_Decrement32s_(ATM) kxAtomic_Decrement32s_(ATM) ///< Macro version of kAtomic_Decrement32s.
112 #define kAtomic_Exchange32s_(ATM, VAL) kxAtomic_Exchange32s_(ATM, VAL) ///< Macro version of kAtomic_Exchange32s.
113 #define kAtomic_CompareExchange32s_(ATM, OLD, VAL) kxAtomic_CompareExchange32s_(ATM, OLD, VAL) ///< Macro version of kAtomic_CompareExchange32s.
114 #define kAtomic_Get32s_(ATM) kxAtomic_Get32s_(ATM) ///< Macro version of kAtomic_Get32s.
115 #define kAtomic_ExchangePointer_(ATM, VAL) kxAtomic_ExchangePointer_(ATM, VAL) ///< Macro version of kAtomic_ExchangePointer.
116 #define kAtomic_CompareExchangePointer_(ATM, OLD, VAL) kxAtomic_CompareExchangePointer_(ATM, OLD, VAL) ///< Macro version of kAtomic_CompareExchangePointer.
117
118 kEndHeader()
119
120 #include <kApi/Threads/kAtomic.x.h>
121
122 #endif
kAtomic::kAtomic_CompareExchange32s
kBool kAtomic_CompareExchange32s(volatile k32s *atomic, k32s oldValue, k32s value)
Conditionally exchanges the value of an atomic variable.
kPointer
Represents a void pointer.
kAtomic::kAtomic_CompareExchangePointer
kBool kAtomic_CompareExchangePointer(volatile kPointer *atomic, kPointer oldValue, kPointer value)
Conditionally exchanges the value of an atomic variable.
kAtomic::kAtomic_Exchange32s
k32s kAtomic_Exchange32s(volatile k32s *atomic, k32s value)
Exchanges the value of an atomic variable.
kApiDef.h
Essential API declarations.
k32s
Represents a 32-bit signed integer.
kAtomic::kAtomic_ExchangePointer
kPointer kAtomic_ExchangePointer(volatile kPointer *atomic, kPointer value)
Exchanges the value of an atomic variable.
kAtomic::kAtomic_Get32s
k32s kAtomic_Get32s(volatile k32s *atomic)
Gets the current value of an atomic variable.
kBool
Represents a boolean value.
kAtomic::kAtomic_Decrement32s
k32s kAtomic_Decrement32s(volatile k32s *atomic)
Decrements an atomic variable.
kAtomic::kAtomic_Increment32s
k32s kAtomic_Increment32s(volatile k32s *atomic)
Increments an atomic variable.