| 1 | Author: Danny Milosavljevic <[email protected]>
|
| 2 | Date: 2025-10-19
|
| 3 | Subject: Work around silly (unused) atomic problem
|
| 4 |
|
| 5 | Exclude static inline functions with atomics from C++ compilation.
|
| 6 |
|
| 7 | block.cpp is the only C++ file in libdispatch and doesn't call the static
|
| 8 | inline functions from lock.h. These functions fail to compile in C++ mode
|
| 9 | because stdatomic.h was only standardized for C++ in C++23. Before C++23,
|
| 10 | stdatomic.h doesn't provide memory_order_* constants. We use GCC's libstdc++
|
| 11 | which only provides C11 atomics in C++23 mode, not in C++11 mode.
|
| 12 |
|
| 13 | Wrap all static inline functions in #ifndef __cplusplus so they are not
|
| 14 | compiled when lock.h is included from C++ files, while keeping the type
|
| 15 | definitions available.
|
| 16 |
|
| 17 | |
| 18 | |
| 19 | @@ -296,6 +296,7 @@
|
| 20 | #endif
|
| 21 | }
|
| 22 |
|
| 23 | +#ifndef __cplusplus
|
| 24 | DISPATCH_ALWAYS_INLINE
|
| 25 | static inline void
|
| 26 | _dispatch_thread_event_signal(dispatch_thread_event_t dte)
|
| 27 | @@ -341,6 +342,7 @@
|
| 28 | _dispatch_sema4_dispose(&dte->dte_sema, _DSEMA4_POLICY_FIFO);
|
| 29 | #endif
|
| 30 | }
|
| 31 | +#endif // __cplusplus
|
| 32 |
|
| 33 | #pragma mark - unfair lock
|
| 34 |
|
| 35 | @@ -348,6 +350,7 @@
|
| 36 | dispatch_lock dul_lock;
|
| 37 | } dispatch_unfair_lock_s, *dispatch_unfair_lock_t;
|
| 38 |
|
| 39 | +#ifndef __cplusplus
|
| 40 | DISPATCH_NOT_TAIL_CALLED
|
| 41 | void _dispatch_unfair_lock_lock_slow(dispatch_unfair_lock_t l,
|
| 42 | dispatch_lock_options_t options);
|
| 43 | @@ -701,5 +704,6 @@
|
| 44 | uint32_t flags);
|
| 45 |
|
| 46 | #endif // TARGET_OS_MAC
|
| 47 | +#endif // __cplusplus
|
| 48 |
|
| 49 | #endif // __DISPATCH_SHIMS_LOCK__
|