io_thread: allow _call() from inside the thread
This commit is contained in:
parent
f3d95f70e2
commit
f3ac8a7cd9
|
@ -107,6 +107,12 @@ io_thread_context(void)
|
||||||
return io.context;
|
return io.context;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
io_thread_inside(void)
|
||||||
|
{
|
||||||
|
return io.thread != NULL && g_thread_self() == io.thread;
|
||||||
|
}
|
||||||
|
|
||||||
guint
|
guint
|
||||||
io_thread_idle_add(GSourceFunc function, gpointer data)
|
io_thread_idle_add(GSourceFunc function, gpointer data)
|
||||||
{
|
{
|
||||||
|
@ -154,6 +160,13 @@ io_thread_call_func(gpointer _data)
|
||||||
gpointer
|
gpointer
|
||||||
io_thread_call(GThreadFunc function, gpointer _data)
|
io_thread_call(GThreadFunc function, gpointer _data)
|
||||||
{
|
{
|
||||||
|
assert(io.thread != NULL);
|
||||||
|
|
||||||
|
if (io_thread_inside())
|
||||||
|
/* we're already in the I/O thread - no
|
||||||
|
synchronization needed */
|
||||||
|
return function(_data);
|
||||||
|
|
||||||
struct call_data data = {
|
struct call_data data = {
|
||||||
.function = function,
|
.function = function,
|
||||||
.data = _data,
|
.data = _data,
|
||||||
|
|
|
@ -52,6 +52,13 @@ G_GNUC_PURE
|
||||||
GMainContext *
|
GMainContext *
|
||||||
io_thread_context(void);
|
io_thread_context(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is the current thread the I/O thread?
|
||||||
|
*/
|
||||||
|
G_GNUC_PURE
|
||||||
|
bool
|
||||||
|
io_thread_inside(void);
|
||||||
|
|
||||||
guint
|
guint
|
||||||
io_thread_idle_add(GSourceFunc function, gpointer data);
|
io_thread_idle_add(GSourceFunc function, gpointer data);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue