Photon Editor Library 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
Threads.h
Go to the documentation of this file.
1#pragma once
2
3#include <Utility/IUninstantiable.h>
4#include <Common/assertion.h>
5
6#include <thread>
7
8namespace ph::editor
9{
10
11class RenderThread;
12
13class Threads final : private IUninstantiable
14{
15public:
19 static bool isOnMainThread();
20
24 static bool isOnRenderThread();
25
31
32private:
33 friend class Program;
34 friend class Application;
35
36 static void setMainThreadID(std::thread::id threadID);
37 static void setRenderThread(RenderThread* threadID);
38
39 static std::thread::id mainThreadID;
40 static std::thread::id renderThreadID;
41 static RenderThread* renderThread;
42
43// Global
44private:
45};
46
48{
49 // Generally should not happen. Except being called outside the editor's domain which should be avoided.
50 PH_ASSERT(mainThreadID != std::thread::id{});
51
52 return std::this_thread::get_id() == mainThreadID;
53}
54
56{
57 // May fail if called before the render thread has been properly initialized.
58 // This can happen if some routine is attempting to use rendering functionalities before
59 // the application starts running.
60 PH_ASSERT(renderThreadID != std::thread::id{});
61
62 return std::this_thread::get_id() == renderThreadID;
63}
64
66{
67 // May fail if called before the render thread has been properly initialized.
68 // This can happen if some routine is attempting to use rendering functionalities before
69 // the application starts running.
70 PH_ASSERT(renderThreadID != std::thread::id{});
71 PH_ASSERT(renderThread);
72
73 return *renderThread;
74}
75
76}// end namespace ph::editor
Definition Application.h:27
Definition Program.h:10
Definition RenderThread.h:25
Definition Threads.h:14
static bool isOnRenderThread()
Whether current thread is the rendering thread.
Definition Threads.h:55
static bool isOnMainThread()
Whether current thread is the thread that called main().
Definition Threads.h:47
static RenderThread & getRenderThread()
Get the rendering thread. It is an error to call this method when the application is not running.
Definition Threads.h:65
Definition ph_editor.h:10