gcc_sync_fenced_block.hpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. //
  2. // detail/gcc_sync_fenced_block.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com)
  6. //
  7. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  8. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  9. //
  10. #ifndef ASIO_DETAIL_GCC_SYNC_FENCED_BLOCK_HPP
  11. #define ASIO_DETAIL_GCC_SYNC_FENCED_BLOCK_HPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include "asio/detail/config.hpp"
  16. #if defined(__GNUC__) \
  17. && ((__GNUC__ == 4 && __GNUC_MINOR__ >= 1) || (__GNUC__ > 4)) \
  18. && !defined(__INTEL_COMPILER) && !defined(__ICL) \
  19. && !defined(__ICC) && !defined(__ECC) && !defined(__PATHSCALE__)
  20. #include "asio/detail/push_options.hpp"
  21. namespace asio {
  22. namespace detail {
  23. class gcc_sync_fenced_block
  24. : private noncopyable
  25. {
  26. public:
  27. enum half_or_full_t { half, full };
  28. // Constructor.
  29. explicit gcc_sync_fenced_block(half_or_full_t)
  30. : value_(0)
  31. {
  32. __sync_lock_test_and_set(&value_, 1);
  33. }
  34. // Destructor.
  35. ~gcc_sync_fenced_block()
  36. {
  37. __sync_lock_release(&value_);
  38. }
  39. private:
  40. int value_;
  41. };
  42. } // namespace detail
  43. } // namespace asio
  44. #include "asio/detail/pop_options.hpp"
  45. #endif // defined(__GNUC__)
  46. // && ((__GNUC__ == 4 && __GNUC_MINOR__ >= 1) || (__GNUC__ > 4))
  47. // && !defined(__INTEL_COMPILER) && !defined(__ICL)
  48. // && !defined(__ICC) && !defined(__ECC) && !defined(__PATHSCALE__)
  49. #endif // ASIO_DETAIL_GCC_SYNC_FENCED_BLOCK_HPP