NexusForce 1.0.0
A Modern C++ Library with extended functionality, web components, and utility libraries
载入中...
搜索中...
未找到
thread_tracker.hpp
浏览该文件的文档.
1#ifndef NEFORCE_CORE_ASYNC_THREAD_TRACKER_HPP__
2#define NEFORCE_CORE_ASYNC_THREAD_TRACKER_HPP__
3
10
12NEFORCE_BEGIN_NAMESPACE__
13
19
25
34class thread_tracker {
35private:
36 static atomic<int> count_;
37
38 friend class thread;
39
40 static NEFORCE_ALWAYS_INLINE void on_thread_create() noexcept { ++count_; }
41
42 static NEFORCE_ALWAYS_INLINE void on_thread_destroy() noexcept { --count_; }
43
44 thread_tracker() {
45 on_thread_create(); // main thread
46 }
47
48 ~thread_tracker() {
49 on_thread_destroy(); // main thread
50 }
51
52public:
59 static thread_tracker& instance() noexcept {
60 static thread_tracker tracker;
61 return tracker;
62 }
63
70 static NEFORCE_ALWAYS_INLINE bool is_single_threaded() noexcept { return instance().count_.load() == 1; }
71
78 static NEFORCE_ALWAYS_INLINE int thread_count() noexcept { return instance().count_.load(); }
79};
80
81
86NEFORCE_ALWAYS_INLINE_INLINE bool is_single_threaded() noexcept { return thread_tracker::is_single_threaded(); }
87
92NEFORCE_ALWAYS_INLINE_INLINE int thread_count() noexcept { return thread_tracker::thread_count(); }
93 // Thread
95 // AsyncComponents
97
98NEFORCE_END_NAMESPACE__
99#endif // NEFORCE_CORE_ASYNC_THREAD_TRACKER_HPP__
原子类型完整实现
static thread_tracker & instance() noexcept
获取线程跟踪器单例实例
static NEFORCE_ALWAYS_INLINE int thread_count() noexcept
获取当前活动线程数量
static NEFORCE_ALWAYS_INLINE bool is_single_threaded() noexcept
检查是否处于单线程模式
NEFORCE_ALWAYS_INLINE_INLINE int thread_count() noexcept
获取当前活动线程数量
NEFORCE_ALWAYS_INLINE_INLINE bool is_single_threaded() noexcept
检查当前是否处于单线程模式
通用原子类型模板
T load(const memory_order mo=memory_order_seq_cst) const noexcept
原子加载操作