FCT
载入中...
搜索中...
未找到
GLFW_UICommon.h
浏览该文件的文档.
1//
2// Created by Administrator on 2025/3/22.
3//
4#include "../ThirdParty.h"
5#ifndef GLFW_UICOMMON_H
6#define GLFW_UICOMMON_H
7namespace FCT{
8
9 using UITaskFunction = std::function<void(void *)>;
10 struct UiTaskData {
12 void *param;
13 std::shared_ptr<bool> waiting;
14 };
21 using UiTicker = std::function<void(void)>;
22
24 public:
27 void postUiTask(UITaskFunction task,void* param = nullptr,bool waited = true);
28 uint32_t postTicker(UiTicker ticker)
29 {
30 uint32_t id = ++m_tickerId;
31 postUiTask([this,ticker,id](void*)
32 {
33 m_ticker[id] = ticker;
34 });
35 return id;
36 }
37 void sendUiTask(UITaskFunction task,void* param = nullptr,bool waited = true)
38 {
39 if (m_uiThreadId == std::this_thread::get_id())
40 {
41 task(param);
42 } else
43 {
44 postUiTask(task, param, waited);
45 }
46 }
47 private:
48 std::thread m_uiThread;
50 boost::lockfree::queue<UITaskTrans, boost::lockfree::capacity<1024>> m_taskQueue;
51 std::unordered_map<uint32_t,UiTicker> m_ticker;
52 uint32_t m_tickerId = 0;
53 std::thread::id m_uiThreadId;
54 };
55
56}
57#endif //GLFW_UICOMMON_H
void postUiTask(UITaskFunction task, void *param=nullptr, bool waited=true)
void sendUiTask(UITaskFunction task, void *param=nullptr, bool waited=true)
std::unordered_map< uint32_t, UiTicker > m_ticker
boost::lockfree::queue< UITaskTrans, boost::lockfree::capacity< 1024 > > m_taskQueue
std::thread::id m_uiThreadId
uint32_t postTicker(UiTicker ticker)
std::function< void(void *)> UITaskFunction
std::function< void(void)> UiTicker
UITaskTrans(UiTaskData *data)
UITaskTrans()=default
std::shared_ptr< bool > waiting