null_thread.hpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. //
  2. // detail/null_thread.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2021 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_NULL_THREAD_HPP
  11. #define BOOST_ASIO_DETAIL_NULL_THREAD_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(BOOST_ASIO_HAS_THREADS)
  17. #include <boost/asio/detail/noncopyable.hpp>
  18. #include <boost/asio/detail/throw_error.hpp>
  19. #include <boost/asio/error.hpp>
  20. #include <boost/asio/detail/push_options.hpp>
  21. namespace boost {
  22. namespace asio {
  23. namespace detail {
  24. class null_thread
  25. : private noncopyable
  26. {
  27. public:
  28. // Constructor.
  29. template <typename Function>
  30. null_thread(Function, unsigned int = 0)
  31. {
  32. boost::asio::detail::throw_error(
  33. boost::asio::error::operation_not_supported, "thread");
  34. }
  35. // Destructor.
  36. ~null_thread()
  37. {
  38. }
  39. // Wait for the thread to exit.
  40. void join()
  41. {
  42. }
  43. // Get number of CPUs.
  44. static std::size_t hardware_concurrency()
  45. {
  46. return 1;
  47. }
  48. };
  49. } // namespace detail
  50. } // namespace asio
  51. } // namespace boost
  52. #include <boost/asio/detail/pop_options.hpp>
  53. #endif // !defined(BOOST_ASIO_HAS_THREADS)
  54. #endif // BOOST_ASIO_DETAIL_NULL_THREAD_HPP