1#ifndef MSTL_CORE_ASYNC_SCOPED_THREAD_HPP__
2#define MSTL_CORE_ASYNC_SCOPED_THREAD_HPP__
34 template <
typename Callable,
typename Object,
typename... Args>
35 static constexpr bool pmf_expects_stop_token = conjunction_v<
53 template <
typename Callable,
typename Object,
typename... Args,
enable_if_t<
54 pmf_expects_stop_token<Callable, Args...>,
int> = 0>
55 static thread create(stop_source& source, Callable func, Object&&
object, Args&&... args) {
68 template <
typename Callable,
typename... Args,
enable_if_t<
69 !pmf_expects_stop_token<Callable, Args...> &&
70 is_invocable_v<decay_t<Callable>, stop_token,
decay_t<Args>...>,
int> = 0>
71 static thread create(stop_source& source, Callable func, Args&&... args) {
83 template <
typename Callable,
typename... Args,
enable_if_t<
84 !pmf_expects_stop_token<Callable, Args...> &&
85 !is_invocable_v<decay_t<Callable>, stop_token,
decay_t<Args>...>,
int> = 0>
86 static thread create(stop_source&, Callable func, Args&&... args) {
89 "jthread arguments must be invocable after conversion to rvalues");
110 template <typename Callable, typename... Args, typename =
enable_if_t<
151 _MSTL swap(stop_source_, other.stop_source_);
160 return thread_.joinable();
186 MSTL_NODISCARD
id get_id() const noexcept {
187 return thread_.get_id();
195 return thread_.native_handle();
211 return stop_source_.get_token();
221 return stop_source_.request_stop();
MSTL_NODISCARD bool joinable() const noexcept
检查线程是否可被等待
void swap(scoped_thread &other) noexcept
交换两个scoped_thread对象
scoped_thread & operator=(const scoped_thread &)=delete
禁止拷贝赋值
MSTL_NODISCARD stop_token get_stop_token() const noexcept
获取停止令牌
bool request_stop() noexcept
请求线程停止
scoped_thread() noexcept=default
默认构造函数
scoped_thread(scoped_thread &&other) noexcept=default
移动构造函数
MSTL_NODISCARD id get_id() const noexcept
获取线程ID
MSTL_NODISCARD native_handle_type native_handle() const
获取原生线程句柄
scoped_thread(const scoped_thread &)=delete
禁止拷贝构造
thread::native_handle_type native_handle_type
原生句柄类型
MSTL_NODISCARD stop_source get_stop_source() noexcept
获取停止源
MSTL_NODISCARD stop_token get_token() const noexcept
获取停止令牌
::pthread_t native_handle_type
系统线程句柄类型
MSTL_NODISCARD constexpr T && forward(remove_reference_t< T > &x) noexcept
完美转发左值
#define _MSTL
全局命名空间MSTL前缀
#define MSTL_END_NAMESPACE__
结束全局命名空间MSTL
#define MSTL_BEGIN_NAMESPACE__
开始全局命名空间MSTL
MSTL_INLINE17 constexpr none_t none
默认空表示
typename remove_cvref< T >::type remove_cvref_t
remove_cvref的便捷别名
constexpr Iterator2 move(Iterator1 first, Iterator1 last, Iterator2 result)
移动范围元素
void swap()=delete
删除无参数的swap重载
typename decay< T >::type decay_t
decay的便捷别名
typename enable_if< Test, T >::type enable_if_t
enable_if的便捷别名