Keep track of which thread the GUI thread is

This commit is contained in:
Robbert van der Helm
2021-07-10 14:21:50 +02:00
parent df75427f69
commit 04a8be6cc6
2 changed files with 16 additions and 0 deletions
+2
View File
@@ -106,6 +106,8 @@ MainContext::MainContext()
}
void MainContext::run() {
gui_thread_id = GetCurrentThreadId();
context.run();
}
+14
View File
@@ -234,6 +234,14 @@ class MainContext {
*/
WatchdogGuard register_watchdog(HostBridge& bridge);
/**
* Returns `true` if the calling thread is the GUI thread, aka the thread
* that called `MainContext::run()`.
*/
inline bool is_gui_thread() const noexcept {
return GetCurrentThreadId() == gui_thread_id.value_or(0);
}
/**
* Asynchronously execute a function inside of this main IO context and
* return the results as a future. This is used to make sure that operations
@@ -316,6 +324,12 @@ class MainContext {
void async_handle_watchdog_timer(
std::chrono::steady_clock::duration interval);
/**
* The **Windows** thread ID the context is running on, which will be our
* GUI thread. Will be a nullopt until `MainContext::run()` has been called.
*/
std::optional<uint32_t> gui_thread_id;
/**
* The timer used to periodically handle X11 events and Win32 messages.
*/