gcc_atomic.hpp 822 B

12345678910111213141516171819202122232425262728293031
  1. //
  2. // MessagePack for C++ old gcc workaround for atomic operation
  3. //
  4. // Copyright (C) 2008-2013 FURUHASHI Sadayuki and KONDO Takatoshi
  5. //
  6. // Distributed under the Boost Software License, Version 1.0.
  7. // (See accompanying file LICENSE_1_0.txt or copy at
  8. // http://www.boost.org/LICENSE_1_0.txt)
  9. //
  10. #ifndef MSGPACK_GCC_ATOMIC_HPP
  11. #define MSGPACK_GCC_ATOMIC_HPP
  12. #if defined(__GNUC__) && ((__GNUC__*10 + __GNUC_MINOR__) < 41)
  13. #include "msgpack/gcc_atomic.h"
  14. #include <bits/atomicity.h>
  15. int _msgpack_sync_decr_and_fetch(volatile _msgpack_atomic_counter_t* ptr)
  16. {
  17. return __gnu_cxx::__exchange_and_add(ptr, -1) - 1;
  18. }
  19. int _msgpack_sync_incr_and_fetch(volatile _msgpack_atomic_counter_t* ptr)
  20. {
  21. return __gnu_cxx::__exchange_and_add(ptr, 1) + 1;
  22. }
  23. #endif // old gcc workaround
  24. #endif /* gcc_atomic.hpp */