Skip to content

Commit 70a8287

Browse files
committed
* convenience macro mulle_thread_once_do added
* _mulle_atomic_pointer_weakcas and sibling functions are now named __mulle_atomic_functionpointer_cas_weak (but the old name still exists) * _mulle_atomic_pointer_nonatomic_write and siblings are now named _mulle_atomic_functionpointer_write_nonatomic but the old names still exist
1 parent 306a492 commit 70a8287

18 files changed

+512
-32
lines changed

.mulle/share/env/environment-plugin.sh

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.mulle/share/env/include-environment.sh

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.mulle/share/env/version

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.mulle/share/sde/version/mulle-sde/cmake

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmake/share/CompilerWarningsC.cmake

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmake/share/DependenciesAndLibraries.cmake

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmake/share/IDESupport.cmake

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmake/share/Motd.cmake

Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/mulle-atomic-c11.h

Lines changed: 62 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,32 @@ typedef _Atomic( mulle_functionpointer_t) mulle_atomic_functionpointer_t;
5454
# pragma mark -
5555
# pragma mark function pointer set and get
5656

57+
// new
58+
MULLE_C_ALWAYS_INLINE static inline mulle_functionpointer_t
59+
_mulle_atomic_functionpointer_read_nonatomic( mulle_atomic_functionpointer_t *p)
60+
{
61+
return( *(mulle_functionpointer_t *) p);
62+
}
63+
64+
65+
// old
5766
MULLE_C_ALWAYS_INLINE static inline mulle_functionpointer_t
5867
_mulle_atomic_functionpointer_nonatomic_read( mulle_atomic_functionpointer_t *p)
5968
{
6069
return( *(mulle_functionpointer_t *) p);
6170
}
6271

6372

73+
// new
74+
MULLE_C_ALWAYS_INLINE static inline void
75+
_mulle_atomic_functionpointer_write_nonatomic( mulle_atomic_functionpointer_t *p,
76+
mulle_functionpointer_t value)
77+
{
78+
*(mulle_functionpointer_t *) p = value;
79+
}
80+
81+
82+
// old
6483
MULLE_C_ALWAYS_INLINE static inline void
6584
_mulle_atomic_functionpointer_nonatomic_write( mulle_atomic_functionpointer_t *p,
6685
mulle_functionpointer_t value)
@@ -118,7 +137,9 @@ MULLE_C_ALWAYS_INLINE static inline mulle_functionpointer_t
118137
memory_order_relaxed);
119138
decor = "";
120139
if( ! result)
121-
decor = "FAILED to";
140+
{
141+
decor = "FAILED to";
142+
}
122143
fprintf( stderr, "%s: %sswap %p %p -> %p (%p)\n",
123144
pthread_name(), decor, address, expect, value, actual);
124145
}
@@ -129,6 +150,7 @@ MULLE_C_ALWAYS_INLINE static inline mulle_functionpointer_t
129150
memory_order_relaxed,
130151
memory_order_relaxed);
131152
#endif
153+
// https://stackoverflow.com/questions/20179315/why-does-stdatomic-compare-exchange-update-the-expected-value
132154
return( actual);
133155
}
134156

@@ -256,6 +278,20 @@ MULLE_C_ALWAYS_INLINE static inline void *
256278
return( *(void **) p);
257279
}
258280

281+
MULLE_C_ALWAYS_INLINE static inline void *
282+
_mulle_atomic_pointer_read_nonatomic( mulle_atomic_pointer_t *p)
283+
{
284+
return( *(void **) p);
285+
}
286+
287+
288+
289+
MULLE_C_ALWAYS_INLINE static inline void
290+
_mulle_atomic_pointer_write_nonatomic( mulle_atomic_pointer_t *p, void *value)
291+
{
292+
*(void **) p = value;
293+
}
294+
259295

260296
MULLE_C_ALWAYS_INLINE static inline void
261297
_mulle_atomic_pointer_nonatomic_write( mulle_atomic_pointer_t *p, void *value)
@@ -293,9 +329,9 @@ MULLE_C_ALWAYS_INLINE static inline void
293329
# pragma mark primitive code
294330

295331
MULLE_C_ALWAYS_INLINE static inline void *
296-
__mulle_atomic_pointer_weakcas( mulle_atomic_pointer_t *address,
297-
void *value,
298-
void *expect)
332+
__mulle_atomic_pointer_cas_weak( mulle_atomic_pointer_t *address,
333+
void *value,
334+
void *expect)
299335
{
300336
void *actual;
301337

@@ -329,10 +365,19 @@ MULLE_C_ALWAYS_INLINE static inline void *
329365
}
330366

331367

368+
MULLE_C_ALWAYS_INLINE static inline void *
369+
__mulle_atomic_pointer_weakcas( mulle_atomic_pointer_t *address,
370+
void *value,
371+
void *expect)
372+
{
373+
return( __mulle_atomic_pointer_cas_weak( address, value, expect));
374+
}
375+
376+
332377
MULLE_C_ALWAYS_INLINE static inline int
333-
_mulle_atomic_pointer_weakcas( mulle_atomic_pointer_t *address,
334-
void *value,
335-
void *expect)
378+
_mulle_atomic_pointer_cas_weak( mulle_atomic_pointer_t *address,
379+
void *value,
380+
void *expect)
336381
{
337382
void *actual;
338383
int result;
@@ -369,6 +414,16 @@ MULLE_C_ALWAYS_INLINE static inline int
369414
}
370415

371416

417+
MULLE_C_ALWAYS_INLINE static inline int
418+
_mulle_atomic_pointer_weakcas( mulle_atomic_pointer_t *address,
419+
void *value,
420+
void *expect)
421+
{
422+
return( _mulle_atomic_pointer_cas_weak( address, value, expect));
423+
}
424+
425+
426+
372427
// this returns actual
373428
MULLE_C_ALWAYS_INLINE static inline void *
374429
__mulle_atomic_pointer_cas( mulle_atomic_pointer_t *address,

src/mulle-atomic-mintomic.h

Lines changed: 82 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,32 @@ typedef void (*mulle_functionpointer_t)();
5858
#pragma mark - value pointers
5959

6060
MULLE_C_ALWAYS_INLINE static inline void *
61-
_mulle_atomic_pointer_nonatomic_read( mulle_atomic_pointer_t *address)
61+
_mulle_atomic_pointer_read_nonatomic( mulle_atomic_pointer_t *address)
6262
{
6363
return( address->_nonatomic);
6464
}
6565

6666

67+
MULLE_C_ALWAYS_INLINE static inline void *
68+
_mulle_atomic_pointer_nonatomic_read( mulle_atomic_pointer_t *address)
69+
{
70+
return( address->_nonatomic);
71+
}
72+
73+
// old
6774
MULLE_C_ALWAYS_INLINE static inline void
6875
_mulle_atomic_pointer_nonatomic_write( mulle_atomic_pointer_t *address, void *value)
6976
{
7077
address->_nonatomic = value;
7178
}
7279

80+
// new
81+
MULLE_C_ALWAYS_INLINE static inline void
82+
_mulle_atomic_pointer_write_nonatomic( mulle_atomic_pointer_t *address, void *value)
83+
{
84+
address->_nonatomic = value;
85+
}
86+
7387

7488
MULLE_C_ALWAYS_INLINE static inline void *
7589
_mulle_atomic_pointer_read( mulle_atomic_pointer_t *address)
@@ -121,6 +135,15 @@ MULLE_C_ALWAYS_INLINE static inline void *
121135
}
122136

123137

138+
MULLE_C_ALWAYS_INLINE static inline void *
139+
__mulle_atomic_pointer_cas_weak( mulle_atomic_pointer_t *address,
140+
void *value,
141+
void *expect)
142+
{
143+
return( __mulle_atomic_pointer_cas( address, value, expect));
144+
}
145+
146+
124147
MULLE_C_ALWAYS_INLINE static inline void *
125148
__mulle_atomic_pointer_weakcas( mulle_atomic_pointer_t *address,
126149
void *value,
@@ -130,6 +153,7 @@ MULLE_C_ALWAYS_INLINE static inline void *
130153
}
131154

132155

156+
133157
MULLE_C_ALWAYS_INLINE static inline int
134158
_mulle_atomic_pointer_cas( mulle_atomic_pointer_t *address,
135159
void *value,
@@ -142,6 +166,15 @@ MULLE_C_ALWAYS_INLINE static inline int
142166
}
143167

144168

169+
MULLE_C_ALWAYS_INLINE static inline int
170+
_mulle_atomic_pointer_cas_weak( mulle_atomic_pointer_t *address,
171+
void *value,
172+
void *expect)
173+
{
174+
return( _mulle_atomic_pointer_cas( address, value, expect));
175+
}
176+
177+
145178
MULLE_C_ALWAYS_INLINE static inline int
146179
_mulle_atomic_pointer_weakcas( mulle_atomic_pointer_t *address,
147180
void *value,
@@ -151,8 +184,19 @@ MULLE_C_ALWAYS_INLINE static inline int
151184
}
152185

153186

187+
154188
#pragma mark - function pointers
155189

190+
// new
191+
MULLE_C_ALWAYS_INLINE static inline mulle_functionpointer_t
192+
_mulle_atomic_functionpointer_read_nonatomic( mulle_atomic_functionpointer_t *address)
193+
{
194+
MULLE_C_ASSERT( sizeof( void *) == sizeof( mulle_functionpointer_t));
195+
196+
return( (mulle_functionpointer_t) _mulle_atomic_pointer_nonatomic_read( (mulle_atomic_pointer_t *) address));
197+
}
198+
199+
// old
156200
MULLE_C_ALWAYS_INLINE static inline mulle_functionpointer_t
157201
_mulle_atomic_functionpointer_nonatomic_read( mulle_atomic_functionpointer_t *address)
158202
{
@@ -162,6 +206,16 @@ MULLE_C_ALWAYS_INLINE static inline mulle_functionpointer_t
162206
}
163207

164208

209+
MULLE_C_ALWAYS_INLINE static inline void
210+
_mulle_atomic_functionpointer_write_nonatomic( mulle_atomic_functionpointer_t *address,
211+
mulle_functionpointer_t value)
212+
{
213+
MULLE_C_ASSERT( sizeof( void *) == sizeof( mulle_functionpointer_t));
214+
215+
_mulle_atomic_pointer_nonatomic_write( (mulle_atomic_pointer_t *) address, (void *) value);
216+
}
217+
218+
165219
MULLE_C_ALWAYS_INLINE static inline void
166220
_mulle_atomic_functionpointer_nonatomic_write( mulle_atomic_functionpointer_t *address,
167221
mulle_functionpointer_t value)
@@ -218,6 +272,17 @@ MULLE_C_ALWAYS_INLINE static inline int
218272
}
219273

220274

275+
MULLE_C_ALWAYS_INLINE static inline int
276+
_mulle_atomic_functionpointer_cas_weak( mulle_atomic_functionpointer_t *address,
277+
mulle_functionpointer_t value,
278+
mulle_functionpointer_t expect)
279+
{
280+
MULLE_C_ASSERT( sizeof( void *) == sizeof( mulle_functionpointer_t));
281+
282+
return( _mulle_atomic_pointer_weakcas( (mulle_atomic_pointer_t *) address, value, expect));
283+
}
284+
285+
221286
MULLE_C_ALWAYS_INLINE static inline int
222287
_mulle_atomic_functionpointer_weakcas( mulle_atomic_functionpointer_t *address,
223288
mulle_functionpointer_t value,
@@ -229,10 +294,11 @@ MULLE_C_ALWAYS_INLINE static inline int
229294
}
230295

231296

297+
232298
MULLE_C_ALWAYS_INLINE static inline mulle_functionpointer_t
233-
__mulle_atomic_functionpointer_weakcas( mulle_atomic_functionpointer_t *address,
234-
mulle_functionpointer_t value,
235-
mulle_functionpointer_t expect)
299+
__mulle_atomic_functionpointer_cas_weak( mulle_atomic_functionpointer_t *address,
300+
mulle_functionpointer_t value,
301+
mulle_functionpointer_t expect)
236302
{
237303
MULLE_C_ASSERT( sizeof( void *) == sizeof( mulle_functionpointer_t));
238304

@@ -242,6 +308,18 @@ MULLE_C_ALWAYS_INLINE static inline mulle_functionpointer_t
242308
}
243309

244310

311+
MULLE_C_ALWAYS_INLINE static inline mulle_functionpointer_t
312+
__mulle_atomic_functionpointer_weakcas( mulle_atomic_functionpointer_t *address,
313+
mulle_functionpointer_t value,
314+
mulle_functionpointer_t expect)
315+
{
316+
MULLE_C_ASSERT( sizeof( void *) == sizeof( mulle_functionpointer_t));
317+
318+
return( (mulle_functionpointer_t) __mulle_atomic_pointer_weakcas( (mulle_atomic_pointer_t *) address,
319+
value,
320+
expect));
321+
}
322+
245323

246324
#pragma mark - atomic arithmetic
247325

0 commit comments

Comments
 (0)