Photon Editor Library 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
EditorEventQueue.h
Go to the documentation of this file.
1#pragma once
2
4
5#include <Utility/Concurrent/TAtomicQuasiQueue.h>
6#include <Utility/TFunction.h>
7
8#include <cstddef>
9#include <vector>
10#include <utility>
11
12namespace ph::editor
13{
14
16{
17public:
18 // Safe limit of concurrent works executed to avoid starvation on main thread works
19 inline constexpr static std::size_t maxAnyThreadWorksPerUpdate = 1024;
20
21 using EventUpdateWork = TFunction<void(void)>;
22
24
28 void add(EventUpdateWork work);
29
36 void flushAllEvents();
37
38private:
39 void updateMainThreadEvents();
40 void updateAnyThreadEvents();
41
42 std::vector<EventUpdateWork> m_mainThreadWorks;
43 TAtomicQuasiQueue<EventUpdateWork> m_anyThreadWorks;
44};
45
47{
49 {
50 m_mainThreadWorks.push_back(std::move(work));
51 }
52 else
53 {
54 m_anyThreadWorks.enqueue(std::move(work));
55 }
56}
57
58}// end namespace ph::editor
Definition EditorEventQueue.h:16
TFunction< void(void)> EventUpdateWork
Definition EditorEventQueue.h:21
void flushAllEvents()
Dequeue and execute added works. There is a limit on the max number of concurrently added (any thread...
Definition EditorEventQueue.cpp:17
static constexpr std::size_t maxAnyThreadWorksPerUpdate
Definition EditorEventQueue.h:19
EditorEventQueue()
Definition EditorEventQueue.cpp:10
void add(EventUpdateWork work)
Definition EditorEventQueue.h:46
static bool isOnMainThread()
Whether current thread is the thread that called main().
Definition Threads.h:47
Definition ph_editor.h:10