NexusForce 1.0.0
A rigorously engineered full-stack C++ backend library.
载入中...
搜索中...
未找到
system_event.hpp
浏览该文件的文档.
1#ifndef NEFORCE_CORE_SYSTEM_SYSTEM_EVENT_HPP__
2#define NEFORCE_CORE_SYSTEM_SYSTEM_EVENT_HPP__
3
10
12#ifdef NEFORCE_PLATFORM_LINUX
14# include <pthread.h>
15#endif
16NEFORCE_BEGIN_NAMESPACE__
17
23
33class NEFORCE_API system_event {
34public:
39 enum class type {
40 manual_reset,
41 auto_reset
42 };
43
44private:
45#ifdef NEFORCE_PLATFORM_LINUX
46 struct mutex_deleter {
47 void operator()(::pthread_mutex_t* m) const noexcept {
48 ::pthread_mutex_destroy(m);
49 delete m;
50 }
51 };
52
53 struct cond_deleter {
54 void operator()(::pthread_cond_t* d) const noexcept {
55 ::pthread_cond_destroy(d);
56 delete d;
57 }
58 };
59#endif
60
61#ifdef NEFORCE_PLATFORM_WINDOWS
62 void* handle_;
63#else
64 unique_ptr<::pthread_mutex_t, mutex_deleter> mutex_;
65 unique_ptr<::pthread_cond_t, cond_deleter> cond_;
66#endif
67 bool signaled_;
68 type type_;
69
70public:
77 explicit system_event(bool initial_state = false, type t = type::auto_reset);
78
83
84 system_event(const system_event&) = delete;
85 system_event& operator=(const system_event&) = delete;
86
91 system_event(system_event&& other) noexcept;
92
99
105 void set() noexcept;
106
110 void reset() noexcept;
111
121 bool wait(uint32_t timeout_ms = numeric_traits<uint32_t>::max()) noexcept;
122
129 bool try_wait() noexcept;
130
135 NEFORCE_NODISCARD bool is_set() const noexcept { return signaled_; }
136
141 NEFORCE_NODISCARD type event_type() const noexcept { return type_; }
142
143#ifdef NEFORCE_PLATFORM_WINDOWS
148 NEFORCE_NODISCARD void* native_handle() const noexcept { return handle_; }
149#endif
150};
151 // SystemEvent
153
154NEFORCE_END_NAMESPACE__
155#endif // NEFORCE_CORE_SYSTEM_SYSTEM_EVENT_HPP__
数值类型极限特性主模板
type event_type() const noexcept
获取事件类型
void reset() noexcept
重置事件为无信号状态
bool wait(uint32_t timeout_ms=numeric_traits< uint32_t >::max()) noexcept
等待事件变为有信号状态
@ auto_reset
自动重置,只唤醒一个等待线程,之后自动重置为无信号
~system_event()
析构函数
system_event & operator=(system_event &&other) noexcept
移动赋值运算符
bool try_wait() noexcept
尝试获取事件(非阻塞)
bool is_set() const noexcept
查询事件是否处于有信号状态
system_event(bool initial_state=false, type t=type::auto_reset)
构造函数
void * native_handle() const noexcept
获取原生事件句柄
system_event(system_event &&other) noexcept
移动构造函数
void set() noexcept
设置事件为有信号状态
constexpr const T & max(const T &a, const T &b, Compare comp) noexcept(noexcept(comp(a, b)))
返回两个值中的较大者
unsigned int uint32_t
32位无符号整数类型
数值特征
独占智能指针