null_thread.hpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. //
  2. // detail/null_thread.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2025 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/throw_error.hpp>
  18. #include <boost/asio/error.hpp>
  19. #include <boost/asio/detail/push_options.hpp>
  20. namespace boost {
  21. namespace asio {
  22. namespace detail {
  23. class null_thread
  24. {
  25. public:
  26. // Construct in a non-joinable state.
  27. null_thread() noexcept
  28. {
  29. }
  30. // Constructor.
  31. template <typename Function>
  32. null_thread(Function, unsigned int = 0)
  33. {
  34. boost::asio::detail::throw_error(
  35. boost::asio::error::operation_not_supported, "thread");
  36. }
  37. // Construct with custom allocator.
  38. template <typename Allocator, typename Function>
  39. null_thread(allocator_arg_t, const Allocator&, Function, unsigned int = 0)
  40. {
  41. boost::asio::detail::throw_error(
  42. boost::asio::error::operation_not_supported, "thread");
  43. }
  44. // Move constructor.
  45. null_thread(null_thread&&) noexcept
  46. {
  47. }
  48. // Destructor.
  49. ~null_thread()
  50. {
  51. }
  52. // Move assignment.
  53. null_thread& operator=(null_thread&&) noexcept
  54. {
  55. return *this;
  56. }
  57. // Whether the thread can be joined.
  58. bool joinable() const
  59. {
  60. return false;
  61. }
  62. // Wait for the thread to exit.
  63. void join()
  64. {
  65. }
  66. // Get number of CPUs.
  67. static std::size_t hardware_concurrency()
  68. {
  69. return 1;
  70. }
  71. };
  72. } // namespace detail
  73. } // namespace asio
  74. } // namespace boost
  75. #include <boost/asio/detail/pop_options.hpp>
  76. #endif // !defined(BOOST_ASIO_HAS_THREADS)
  77. #endif // BOOST_ASIO_DETAIL_NULL_THREAD_HPP