gcc_fenced_block.hpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. //
  2. // gcc_fenced_block.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2010 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_FENCED_BLOCK_HPP
  11. #define ASIO_DETAIL_GCC_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/push_options.hpp"
  16. #include "asio/detail/push_options.hpp"
  17. #include <boost/config.hpp>
  18. #include "asio/detail/pop_options.hpp"
  19. #if defined(__GNUC__) \
  20. && ((__GNUC__ == 4 && __GNUC_MINOR__ >= 1) || (__GNUC__ > 4)) \
  21. && !defined(__INTEL_COMPILER) && !defined(__ICL) \
  22. && !defined(__ICC) && !defined(__ECC) && !defined(__PATHSCALE__)
  23. namespace asio {
  24. namespace detail {
  25. class gcc_fenced_block
  26. : private noncopyable
  27. {
  28. public:
  29. // Constructor.
  30. gcc_fenced_block()
  31. : value_(0)
  32. {
  33. __sync_lock_test_and_set(&value_, 1);
  34. }
  35. // Destructor.
  36. ~gcc_fenced_block()
  37. {
  38. __sync_lock_release(&value_);
  39. }
  40. private:
  41. int value_;
  42. };
  43. } // namespace detail
  44. } // namespace asio
  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. #include "asio/detail/pop_options.hpp"
  50. #endif // ASIO_DETAIL_GCC_FENCED_BLOCK_HPP