mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-05-16 21: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() {
|
void MainContext::run() {
|
||||||
|
gui_thread_id = GetCurrentThreadId();
|
||||||
|
|
||||||
context.run();
|
context.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -234,6 +234,14 @@ class MainContext {
|
|||||||
*/
|
*/
|
||||||
WatchdogGuard register_watchdog(HostBridge& bridge);
|
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
|
* 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
|
* 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(
|
void async_handle_watchdog_timer(
|
||||||
std::chrono::steady_clock::duration interval);
|
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.
|
* The timer used to periodically handle X11 events and Win32 messages.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user