diff options
author | Marc-André Lureau <marcandre.lureau@redhat.com> | 2010-12-02 18:59:24 +0100 |
---|---|---|
committer | Marc-André Lureau <marcandre.lureau@redhat.com> | 2010-12-05 18:15:22 +0100 |
commit | e0e77b800e5ac18f7e970b4ff70dd910972eba71 (patch) | |
tree | a327865ccbdea1da4072320b19dcf4e9a253f82a /gtk/gio-coroutine.h | |
parent | a08d433772c1df26fa159be56cb880c5402ed792 (diff) |
gtk: WIP use coroutines and GSocket to connect
Diffstat (limited to 'gtk/gio-coroutine.h')
-rw-r--r-- | gtk/gio-coroutine.h | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/gtk/gio-coroutine.h b/gtk/gio-coroutine.h new file mode 100644 index 0000000..ec9faa9 --- /dev/null +++ b/gtk/gio-coroutine.h @@ -0,0 +1,61 @@ +/* -*- Mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */ +/* + Copyright (C) 2010 Red Hat, Inc. + Copyright (C) 2006 Anthony Liguori <anthony@codemonkey.ws> + Copyright (C) 2009-2010 Daniel P. Berrange <dan@berrange.com> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ +#ifndef __GIO_COROUTINE_H__ +#define __GIO_COROUTINE_H__ + +#include <gio/gio.h> +#include "coroutine.h" + +G_BEGIN_DECLS + +struct wait_queue +{ + gboolean waiting; + struct coroutine *context; +}; + +/* + * A special GSource impl which allows us to wait on a certain + * condition to be satisfied. This is effectively a boolean test + * run on each iteration of the main loop. So whenever a file has + * new I/O, or a timer occurs, etc we'll do the check. This is + * pretty efficient compared to a normal GLib Idle func which has + * to busy wait on a timeout, since our condition is only checked + * when some other source's state changes + */ +typedef gboolean (*g_condition_wait_func)(gpointer); + +struct g_condition_wait_source +{ + GSource src; + struct coroutine *co; + g_condition_wait_func func; + gpointer data; +}; + +GIOCondition g_io_wait (GSocket *sock, GIOCondition cond); +gboolean g_condition_wait (g_condition_wait_func func, gpointer data); +void g_io_wakeup (struct wait_queue *wait); +GIOCondition g_io_wait_interruptable(struct wait_queue *wait, GSocket *sock, GIOCondition cond); + +G_END_DECLS + +#endif /* __GIO_COROUTINE_H__ */ |