Lumiera
0.pre.03
»edit your freedom«
|
Go to the source code of this file.
Allow dispatch of self-contained code blocks (lambdas) into the main UI event thread.
GTK is not threadsafe by design – thus it is mandatory to dispatch any asynchronous invocations from external facilities in a controlled way into the main event loop. Unfortunately, this becomes a tricky undertaking when these external invocations need to pass argument data. This helper serves to accommodate such problems, relying on the automatic (heap based) argument storage of std::function. Client code provides the actual invocation in the form of completely closed lambdas.
Basically the implementation relies on the standard mechanism for multithreaded UI applications. But on top we use our own dispatcher queue to allow passing arbitrary argument data, based on the argument storage of std::function
. Which in the end effectively involves two disjoint thread collaboration mechanisms:
std::function
instancemagic'', the dispatcher hooks into the respective GLib
main context'' to ensure this signalling is picked up from the event thread, which...This hybrid approach is rather simple to establish, but creates additional complexities at runtime. More specifically, we have to pay the penalty of chaining the overhead and the inherent limitations of two thread signalling mechanisms (in our dispatcher queue and within kernel based IO). It would be conceivable to implement all of the hand-over mechanism solely within our framework, yet unfortunately there seems to be no easily accessible and thus ``official'' way to hook into the event processing, at least without digging deep into GLib internals.
Definition in file ui-dispatcher.hpp.
#include "stage/gtk-base.hpp"
#include "lib/call-queue.hpp"
#include "lib/format-string.hpp"
#include "lib/nocopy.hpp"
#include <utility>
Classes | |
class | UiDispatcher |
Helper to dispatch code blocks into the UI event thread for execution. More... | |
Functions | |
string | generateErrorResponse (const char *problem="unexpected problem") |
Namespaces | |
stage | |
Lumiera GTK UI implementation root. | |
stage::ctrl | |
Backbone of the Lumiera GTK UI. | |