gcc_atomic.hpp 790 B

123456789101112131415161718192021222324252627282930
  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 <bits/atomicity.h>
  14. int _msgpack_sync_decr_and_fetch(volatile _msgpack_atomic_counter_t* ptr)
  15. {
  16. return __gnu_cxx::__exchange_and_add(ptr, -1) - 1;
  17. }
  18. int _msgpack_sync_incr_and_fetch(volatile _msgpack_atomic_counter_t* ptr)
  19. {
  20. return __gnu_cxx::__exchange_and_add(ptr, 1) + 1;
  21. }
  22. #endif // old gcc workaround
  23. #endif /* gcc_atomic.hpp */