mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-05-07 03:50:11 +02:00
Keep track of which thread the GUI thread is
This commit is contained in:
@@ -106,6 +106,8 @@ MainContext::MainContext()
|
||||
}
|
||||
|
||||
void MainContext::run() {
|
||||
gui_thread_id = GetCurrentThreadId();
|
||||
|
||||
context.run();
|
||||
}
|
||||
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user