Re: Mainloop ownership



On Saturday 11 November 2006 22:45, Matt Hoosier wrote:
> I have a Gtk widget library whose API can be called asynchronously.
> Part of its implementation uses GConf, which I'm pretty sure
> [http://developer.gnome.org/doc/API/gconf/c119.html] is intended only
> to be used from a single thread.
>
> I would like to make the async-safe API perform its work by making
> direct calls when it's called from the Gtk mainloop thread, and
> alternately by queueing an idle handler and waiting for a return
> signal when the call comes from outside the mainloop thread.
>
> If one is using a GMainLoop directly, you can test which thread you're
> in by doing
>
>   g_main_context_is_owner (g_main_loop_get_context (loop))
>
> but gtkmain.c completely encapsulates the loop object (making the test
> above impossible), and I'm a little stumped on how to determine
> whether the caller is the Gtk main thread. Any ideas?

g_thread_self() will tell you (assuming you have previously stored the GThread 
object for the main thread to compare it against).

Chris




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]