Moves work from service threads (gRPC, HTTP) onto the UI thread. More...
#include <ui_thread_queue.h>
Classes | |
| struct | Call |
| struct | Entry |
| struct | IsStatusOr |
| struct | IsStatusOr< absl::StatusOr< T > > |
Public Member Functions | |
| UiThreadQueue ()=default | |
| ~UiThreadQueue () | |
| UiThreadQueue (const UiThreadQueue &)=delete | |
| UiThreadQueue & | operator= (const UiThreadQueue &)=delete |
| void | BindToCurrentThread () |
| bool | IsUiThread () const |
| bool | RunsInline () const |
| void | SetWaker (std::function< void()> waker) |
| bool | Post (std::function< void()> task) |
| size_t | Drain () |
| bool | HasPendingTasks () const |
| void | Shutdown () |
| bool | IsShutdown () const |
| template<typename Fn , typename R = std::invoke_result_t<Fn&>> | |
| R | RunOnUiThread (Fn fn, std::chrono::milliseconds timeout=kDefaultTimeout) |
| Runs fn on the UI thread and returns its result. | |
Static Public Member Functions | |
| static UiThreadQueue & | Get () |
Static Public Attributes | |
| static constexpr std::chrono::milliseconds | kDefaultTimeout {5000} |
Private Member Functions | |
| absl::Status | RunAndWait (std::function< void()> body, std::chrono::milliseconds timeout) |
| bool | Enqueue (Entry entry) |
| void | Wake () |
Private Attributes | |
| std::mutex | mu_ |
| std::deque< Entry > | queue_ |
| std::thread::id | ui_thread_id_ |
| bool | bound_ = false |
| bool | shutdown_ = false |
| std::mutex | waker_mu_ |
| std::function< void()> | waker_ |
Moves work from service threads (gRPC, HTTP) onto the UI thread.
Editor, canvas and ROM state is owned by the thread that runs the frame loop. Socket threads must not touch it directly, so they hand a task to this queue and the Controller runs it at the start of the next frame, before ImGui::NewFrame().
Lifecycle:
Get() returns the process-wide instance. A singleton is used because the gRPC and HTTP services are built by Application, apart from the Controller, and need to reach the same queue without new constructor plumbing. Tests construct their own UiThreadQueue instances.
Definition at line 44 of file ui_thread_queue.h.
|
default |
Referenced by Get().
| yaze::util::UiThreadQueue::~UiThreadQueue | ( | ) |
Definition at line 9 of file ui_thread_queue.cc.
References Shutdown().

|
delete |
|
delete |
|
static |
Definition at line 16 of file ui_thread_queue.cc.
References UiThreadQueue().
Referenced by yaze::Controller::OnEntry(), yaze::Controller::OnExit(), yaze::Controller::OnInput(), yaze::Controller::OnLoad(), and yaze::Controller::RequestScreenshot().

| void yaze::util::UiThreadQueue::BindToCurrentThread | ( | ) |
Definition at line 23 of file ui_thread_queue.cc.
References bound_, mu_, shutdown_, and ui_thread_id_.
| bool yaze::util::UiThreadQueue::IsUiThread | ( | ) | const |
Definition at line 30 of file ui_thread_queue.cc.
References bound_, mu_, and ui_thread_id_.
| bool yaze::util::UiThreadQueue::RunsInline | ( | ) | const |
Definition at line 35 of file ui_thread_queue.cc.
References bound_, mu_, shutdown_, and ui_thread_id_.
| void yaze::util::UiThreadQueue::SetWaker | ( | std::function< void()> | waker | ) |
Definition at line 46 of file ui_thread_queue.cc.
References waker_, and waker_mu_.
Referenced by yaze::Controller::OnEntry().
| bool yaze::util::UiThreadQueue::Post | ( | std::function< void()> | task | ) |
Definition at line 53 of file ui_thread_queue.cc.
References Enqueue().
Referenced by yaze::Controller::RequestScreenshot().

| size_t yaze::util::UiThreadQueue::Drain | ( | ) |
Definition at line 87 of file ui_thread_queue.cc.
Referenced by yaze::Controller::OnLoad().
| bool yaze::util::UiThreadQueue::HasPendingTasks | ( | ) | const |
Definition at line 101 of file ui_thread_queue.cc.
Referenced by yaze::Controller::OnInput().
| void yaze::util::UiThreadQueue::Shutdown | ( | ) |
Definition at line 106 of file ui_thread_queue.cc.
References yaze::util::UiThreadQueue::Call::kCancelled, yaze::util::UiThreadQueue::Call::kPending, mu_, queue_, and shutdown_.
Referenced by yaze::Controller::OnLoad(), and ~UiThreadQueue().
| bool yaze::util::UiThreadQueue::IsShutdown | ( | ) | const |
Definition at line 127 of file ui_thread_queue.cc.
|
inline |
Runs fn on the UI thread and returns its result.
fn must return absl::Status or absl::StatusOr<T>.
Definition at line 111 of file ui_thread_queue.h.
References RunAndWait().

|
private |
Definition at line 132 of file ui_thread_queue.cc.
References bound_, yaze::util::UiThreadQueue::Entry::call, Enqueue(), yaze::util::UiThreadQueue::Call::kAbandoned, yaze::util::UiThreadQueue::Call::kCancelled, yaze::util::UiThreadQueue::Call::kDone, yaze::util::UiThreadQueue::Call::kPending, yaze::util::UiThreadQueue::Call::kRunning, mu_, shutdown_, yaze::util::UiThreadQueue::Entry::task, and ui_thread_id_.
Referenced by RunOnUiThread().

|
private |
Definition at line 60 of file ui_thread_queue.cc.
References mu_, queue_, shutdown_, and Wake().
Referenced by Post(), and RunAndWait().

|
private |
Definition at line 80 of file ui_thread_queue.cc.
References waker_, and waker_mu_.
Referenced by Enqueue().
|
staticconstexpr |
Definition at line 48 of file ui_thread_queue.h.
|
mutableprivate |
Definition at line 155 of file ui_thread_queue.h.
Referenced by BindToCurrentThread(), Drain(), Enqueue(), HasPendingTasks(), IsShutdown(), IsUiThread(), RunAndWait(), RunsInline(), and Shutdown().
|
private |
Definition at line 156 of file ui_thread_queue.h.
Referenced by Drain(), Enqueue(), HasPendingTasks(), and Shutdown().
|
private |
Definition at line 157 of file ui_thread_queue.h.
Referenced by BindToCurrentThread(), IsUiThread(), RunAndWait(), and RunsInline().
|
private |
Definition at line 158 of file ui_thread_queue.h.
Referenced by BindToCurrentThread(), IsUiThread(), RunAndWait(), and RunsInline().
|
private |
Definition at line 159 of file ui_thread_queue.h.
Referenced by BindToCurrentThread(), Enqueue(), IsShutdown(), RunAndWait(), RunsInline(), and Shutdown().
|
private |
Definition at line 162 of file ui_thread_queue.h.
Referenced by SetWaker(), and Wake().
|
private |
Definition at line 163 of file ui_thread_queue.h.
Referenced by SetWaker(), and Wake().