gcc_sync_fenced_block.hpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. //
  2. // detail/gcc_sync_fenced_block.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2013 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 BOOST_ASIO_DETAIL_GCC_SYNC_FENCED_BLOCK_HPP
  11. #define BOOST_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 <boost/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 <boost/asio/detail/push_options.hpp>
  21. namespace boost {
  22. namespace asio {
  23. namespace detail {
  24. class gcc_sync_fenced_block
  25. : private noncopyable
  26. {
  27. public:
  28. enum half_or_full_t { half, full };
  29. // Constructor.
  30. explicit gcc_sync_fenced_block(half_or_full_t)
  31. : value_(0)
  32. {
  33. __sync_lock_test_and_set(&value_, 1);
  34. }
  35. // Destructor.
  36. ~gcc_sync_fenced_block()
  37. {
  38. __sync_lock_release(&value_);
  39. }
  40. private:
  41. int value_;
  42. };
  43. } // namespace detail
  44. } // namespace asio
  45. } // namespace boost
  46. #include <boost/asio/detail/pop_options.hpp>
  47. #endif // defined(__GNUC__)
  48. // && ((__GNUC__ == 4 && __GNUC_MINOR__ >= 1) || (__GNUC__ > 4))
  49. // && !defined(__INTEL_COMPILER) && !defined(__ICL)
  50. // && !defined(__ICC) && !defined(__ECC) && !defined(__PATHSCALE__)
  51. #endif // BOOST_ASIO_DETAIL_GCC_SYNC_FENCED_BLOCK_HPP