|
28 | 28 | #include <memory> |
29 | 29 | #include <stdexcept> |
30 | 30 |
|
| 31 | +#if !defined(MSGPACK_USE_CPP03) |
| 32 | +#include <atomic> |
| 33 | +#endif |
| 34 | + |
| 35 | + |
31 | 36 | #if defined(_MSC_VER) |
32 | 37 | // avoiding confliction std::max, std::min, and macro in windows.h |
33 | 38 | #ifndef NOMINMAX |
@@ -349,25 +354,46 @@ class unpack_stack { |
349 | 354 |
|
350 | 355 | inline void init_count(void* buffer) |
351 | 356 | { |
| 357 | +#if defined(MSGPACK_USE_CPP03) |
352 | 358 | *reinterpret_cast<volatile _msgpack_atomic_counter_t*>(buffer) = 1; |
| 359 | +#else // defined(MSGPACK_USE_CPP03) |
| 360 | + new (buffer) std::atomic<unsigned int>(1); |
| 361 | +#endif // defined(MSGPACK_USE_CPP03) |
353 | 362 | } |
354 | 363 |
|
355 | 364 | inline void decr_count(void* buffer) |
356 | 365 | { |
| 366 | +#if defined(MSGPACK_USE_CPP03) |
357 | 367 | if(_msgpack_sync_decr_and_fetch(reinterpret_cast<volatile _msgpack_atomic_counter_t*>(buffer)) == 0) { |
358 | 368 | free(buffer); |
359 | 369 | } |
| 370 | +#else // defined(MSGPACK_USE_CPP03) |
| 371 | + if (--*reinterpret_cast<std::atomic<unsigned int>*>(buffer) == 0) { |
| 372 | + free(buffer); |
| 373 | + } |
| 374 | +#endif // defined(MSGPACK_USE_CPP03) |
360 | 375 | } |
361 | 376 |
|
362 | 377 | inline void incr_count(void* buffer) |
363 | 378 | { |
| 379 | +#if defined(MSGPACK_USE_CPP03) |
364 | 380 | _msgpack_sync_incr_and_fetch(reinterpret_cast<volatile _msgpack_atomic_counter_t*>(buffer)); |
| 381 | +#else // defined(MSGPACK_USE_CPP03) |
| 382 | + ++*reinterpret_cast<std::atomic<unsigned int>*>(buffer); |
| 383 | +#endif // defined(MSGPACK_USE_CPP03) |
365 | 384 | } |
366 | 385 |
|
| 386 | +#if defined(MSGPACK_USE_CPP03) |
367 | 387 | inline _msgpack_atomic_counter_t get_count(void* buffer) |
368 | 388 | { |
369 | 389 | return *reinterpret_cast<volatile _msgpack_atomic_counter_t*>(buffer); |
370 | 390 | } |
| 391 | +#else // defined(MSGPACK_USE_CPP03) |
| 392 | +inline std::atomic<unsigned int> const& get_count(void* buffer) |
| 393 | +{ |
| 394 | + return *reinterpret_cast<std::atomic<unsigned int>*>(buffer); |
| 395 | +} |
| 396 | +#endif // defined(MSGPACK_USE_CPP03) |
371 | 397 |
|
372 | 398 | struct fix_tag { |
373 | 399 | char f1[65]; // FIXME unique size is required. or use is_same meta function. |
|
0 commit comments