CoriEngine
Loading...
Searching...
No Matches
MainThreadComandQueue.hpp
Go to the documentation of this file.
1#pragma once
2
3#if 1
4namespace Cori {
5 namespace Core {
6 namespace Threading {
8 public:
9 template <class F, class... Args>
10 std::future<std::invoke_result_t<F, Args...>> Submit(F&& f, Args&&... args) {
11 using ReturnType = std::invoke_result_t<F, Args...>;
12
13 auto task = std::make_shared<std::packaged_task<ReturnType()>>(
14 std::bind(std::forward<F>(f), std::forward<Args>(args)...)
15 );
16
17 std::future<ReturnType> res = task->get_future();
18
19 {
20 std::unique_lock lock(m_Mutex);
21
22 m_Tasks.emplace_back([task]() {
23 (*task)();
24 });
25 }
26
27 return res;
28 }
29
30 void Execute() {
32 std::deque<std::function<void()>> copy;
33 {
34 std::lock_guard lock(m_Mutex);
35 copy.swap(m_Tasks);
36 }
37
38 for (const auto& task : copy) {
39 task();
40 }
41 }
42 private:
43 std::deque<std::function<void()>> m_Tasks;
44 std::mutex m_Mutex;
45 };
46 }
47 }
48}
49#endif
#define CORI_PROFILE_FUNCTION()
Definition Profiler.hpp:9
std::future< std::invoke_result_t< F, Args... > > Submit(F &&f, Args &&... args)
Core systems of the engine are here.
Global engine namespace.