Skip to content

Commit ea6a195

Browse files
committed
Fix a compilation error (redefinition of memory_order_xxx) on macOS with C++98
1 parent 698ac49 commit ea6a195

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

src/concurrent.hpp

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ limitations under the License.
3636
#define CONCURRENCY_ENABLED
3737
#endif
3838
#endif
39+
#else
40+
#define CONCURRENT_FALLBACK_ATOMICS
3941
#endif
4042

4143

@@ -202,15 +204,11 @@ class Task {
202204
#endif
203205

204206

205-
#if defined(CONCURRENCY_ENABLED) || (__cplusplus >= 201103L) || (defined(_MSC_VER) && _MSC_VER >= 1700)
206-
#include <atomic>
207-
#define ATOMIC_INT std::atomic_int
208-
#define ATOMIC_BOOL std::atomic_bool
209-
210-
#else
207+
#ifdef CONCURRENT_FALLBACK_ATOMICS
211208
// ! Stubs for NON CONCURRENT USAGE !
212209
// Used when compiling for older C++ standards (C++98/03)
213210

211+
/*
214212
// Use enum instead of const int to prevent linkage issues
215213
enum fallback_memory_order {
216214
memory_order_relaxed = 0,
@@ -220,6 +218,8 @@ class Task {
220218
memory_order_acq_rel = 4,
221219
memory_order_seq_cst = 5
222220
};
221+
*/
222+
223223

224224
// Naming the class 'fallback_...' avoids conflicts if the macro
225225
// matches the class name recursively in some preprocessors.
@@ -247,13 +247,13 @@ class Task {
247247
return _n;
248248
}
249249

250-
int load(int mo = memory_order_relaxed) const
250+
int load(int mo = 0 /*memory_order_relaxed*/) const
251251
{
252252
(void)mo;
253253
return _n;
254254
}
255255

256-
void store(int n, int mo = memory_order_release)
256+
void store(int n, int mo = 3 /*memory_order_release*/)
257257
{
258258
(void)mo;
259259
_n = n;
@@ -274,15 +274,15 @@ class Task {
274274
}
275275

276276
// Standard signature: takes int delta, returns OLD value
277-
int fetch_add(int delta, int mo = memory_order_seq_cst)
277+
int fetch_add(int delta, int mo = 5 /*memory_order_seq_cst*/)
278278
{
279279
(void)mo;
280280
int old = _n;
281281
_n += delta;
282282
return old;
283283
}
284284

285-
int fetch_sub(int delta, int mo = memory_order_seq_cst)
285+
int fetch_sub(int delta, int mo = 5 /*memory_order_seq_cst*/)
286286
{
287287
(void)mo;
288288
int old = _n;
@@ -291,7 +291,7 @@ class Task {
291291
}
292292

293293
// CRITICAL FIX: Must update 'expected' on failure
294-
bool compare_exchange_strong(int& expected, int desired, int mo = memory_order_seq_cst)
294+
bool compare_exchange_strong(int& expected, int desired, int mo = 5 /*memory_order_seq_cst*/)
295295
{
296296
(void)mo;
297297

@@ -304,7 +304,7 @@ class Task {
304304
}
305305
}
306306

307-
bool compare_exchange_weak(int& expected, int desired, int mo = memory_order_seq_cst)
307+
bool compare_exchange_weak(int& expected, int desired, int mo = 5 /*memory_order_seq_cst*/)
308308
{
309309
return compare_exchange_strong(expected, desired, mo);
310310
}
@@ -331,27 +331,27 @@ class Task {
331331
return _b;
332332
}
333333

334-
bool load(int mo = memory_order_relaxed) const
334+
bool load(int mo = 0 /*memory_order_relaxed*/) const
335335
{
336336
(void)mo;
337337
return _b;
338338
}
339339

340-
void store(bool b, int mo = memory_order_release)
340+
void store(bool b, int mo = 3 /*memory_order_release*/)
341341
{
342342
(void)mo;
343343
_b = b;
344344
}
345345

346-
bool exchange(bool val, int mo = memory_order_acquire)
346+
bool exchange(bool val, int mo = 2 /*memory_order_acquire*/)
347347
{
348348
(void)mo;
349349
bool old = _b;
350350
_b = val;
351351
return old;
352352
}
353353

354-
bool compare_exchange_strong(bool& expected, bool desired, int mo = memory_order_seq_cst)
354+
bool compare_exchange_strong(bool& expected, bool desired, int mo = 5 /*memory_order_seq_cst*/)
355355
{
356356
(void)mo;
357357
if (_b == expected) {
@@ -366,6 +366,9 @@ class Task {
366366

367367
#define ATOMIC_INT fallback_atomic_int
368368
#define ATOMIC_BOOL fallback_atomic_bool
369+
#else
370+
#define ATOMIC_INT std::atomic_int
371+
#define ATOMIC_BOOL std::atomic_bool
369372

370373
#endif
371374

0 commit comments

Comments
 (0)