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 /* ------------------------------------------------------------------------- */
37 /* ------------------------------------------------------------------------- */
38 virtual void OnCompleted(uint32_t index, const Node *node) noexcept = 0;
39};
40
41
43class Thread
44{
45public:
46 Thread(ThreadListener &listener, uint32_t index) noexcept;
47
48 ~Thread() noexcept;
49
50 bool Create() noexcept;
51
52 bool Execute(Node *taskNode, ExecuteStage stage) noexcept;
53
54private:
55 void Process() noexcept;
56
57 ThreadListener &_listener;
58 uint32_t _index;
59
60 std::atomic<bool> _shouldExit{false};
61 Node *_taskNode{nullptr};
62 ExecuteStage _stage{0};
63
64 std::atomic<bool> _isExecuting{false};
65
66 std::mutex _mutex;
67 std::condition_variable _condition;
68
69 std::thread _thread;
70};
71} // namespace MGL::Task
72
73#endif // INCGUARD_MGL_TASK_THREAD_H_1699019667
74
75// vim: et ts=4 sw=4 sts=4
タスクノード
Definition mgl_task_node.h:20
タスクノード並列実行用スレッド
Definition mgl_task_thread.h:44
bool Create() noexcept
スレッドの生成
Definition mgl_task_thread.cc:55
Thread(ThreadListener &listener, uint32_t index) noexcept
コンストラクタ
Definition mgl_task_thread.cc:22
bool Execute(Node *taskNode, ExecuteStage stage) noexcept
タスクノードの実行
Definition mgl_task_thread.cc:82
~Thread() noexcept
デストラクタ
Definition mgl_task_thread.cc:34
スレッドからの通知を受けるためのリスナークラス
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