MGL(Win32)
読み取り中…
検索中…
一致する文字列を見つけられません
mgl_task_thread.h
[詳解]
1// SPDX-License-Identifier: Zlib
2/* ------------------------------------------------------------------------- */
9/* ------------------------------------------------------------------------- */
10
11#ifndef INCGUARD_MGL_TASK_THREAD_H_1699019667
12#define INCGUARD_MGL_TASK_THREAD_H_1699019667
13
14#include <atomic>
15#include <condition_variable>
16#include <mutex>
17#include <thread>
18
20
21namespace MGL::Task
22{
23class Node;
24class Thread;
25
28{
29public:
30 virtual ~ThreadListener() noexcept = default;
31
32 /* ------------------------------------------------------------------------- */
38 /* ------------------------------------------------------------------------- */
39 virtual void OnCompleted(uint32_t index, const Node *node) noexcept = 0;
40};
41
42
44class Thread
45{
46public:
47 Thread(ThreadListener &listener, uint32_t index) noexcept;
48
49 ~Thread() noexcept;
50
51 bool Create() noexcept;
52
53 bool Execute(Node *taskNode, ExecuteStage stage) noexcept;
54
55private:
56 void Process() noexcept;
57
58 ThreadListener &_listener;
59 uint32_t _index;
60
61 std::atomic<bool> _shouldExit{false};
62 Node *_taskNode{nullptr};
63 ExecuteStage _stage{0};
64
65 std::atomic<bool> _isExecuting{false};
66
67 std::mutex _mutex;
68 std::condition_variable _condition;
69
70 std::thread _thread;
71};
72} // namespace MGL::Task
73
74#endif // INCGUARD_MGL_TASK_THREAD_H_1699019667
75
76// vim: et ts=4 sw=4 sts=4
タスクノード
Definition mgl_task_node.h:20
タスクノード並列実行用スレッド
Definition mgl_task_thread.h:45
bool Create() noexcept
スレッドの生成
Definition mgl_task_thread.cc:55
Thread(ThreadListener &listener, uint32_t index) noexcept
コンストラクタ
Definition mgl_task_thread.cc:24
bool Execute(Node *taskNode, ExecuteStage stage) noexcept
タスクノードの実行
Definition mgl_task_thread.cc:82
~Thread() noexcept
デストラクタ
Definition mgl_task_thread.cc:35
スレッドからの通知を受けるためのリスナークラス
Definition mgl_task_thread.h:28
virtual void OnCompleted(uint32_t index, const Node *node) noexcept=0
完了通知
MGL タスク関連定義
uint8_t ExecuteStage
実行ステージ
Definition mgl_task_defs.h:68