1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- #ifndef __ASIO2_THREAD_ID_COMPONENT_HPP__
- #define __ASIO2_THREAD_ID_COMPONENT_HPP__
- #if defined(_MSC_VER) && (_MSC_VER >= 1200)
- #pragma once
- #endif
- #include <thread>
- #include <asio2/base/error.hpp>
- namespace asio2::detail
- {
- template<class derived_t, class args_t = void>
- class thread_id_cp
- {
- public:
-
- thread_id_cp() = default;
-
- ~thread_id_cp() = default;
- thread_id_cp(thread_id_cp&&) noexcept = default;
- thread_id_cp(thread_id_cp const&) = default;
- thread_id_cp& operator=(thread_id_cp&&) noexcept = default;
- thread_id_cp& operator=(thread_id_cp const&) = default;
- public:
-
- inline bool running_in_this_thread() const noexcept
- {
- derived_t& derive = const_cast<derived_t&>(static_cast<const derived_t&>(*this));
- return (derive.io_->get_thread_id() == std::this_thread::get_id());
- }
-
- inline std::thread::id get_thread_id() const noexcept
- {
- derived_t& derive = const_cast<derived_t&>(static_cast<const derived_t&>(*this));
- return derive.io_->get_thread_id();
- }
- protected:
- };
- }
- #endif
|