source: select.c @ c66ec48

Last change on this file since c66ec48 was c5c5686, checked in by David Benjamin <davidben@mit.edu>, 10 years ago
And finally, remove owl_io_dispatch All uses have been replaced with a GIOChannel watch.
  • Property mode set to 100644
File size: 1.2 KB
Line 
1#include "owl.h"
2
3static GMainLoop *loop = NULL;
4static GMainContext *main_context;
5
6void owl_select_init(void)
7{
8}
9
10void owl_select_run_loop(void)
11{
12  main_context = g_main_context_default();
13  loop = g_main_loop_new(main_context, FALSE);
14  g_main_loop_run(loop);
15}
16
17void owl_select_quit_loop(void)
18{
19  if (loop) {
20    g_main_loop_quit(loop);
21    loop = NULL;
22  }
23}
24
25typedef struct _owl_task { /*noproto*/
26  void (*cb)(void *);
27  void *cbdata;
28  void (*destroy_cbdata)(void *);
29} owl_task;
30
31static gboolean _run_task(gpointer data)
32{
33  owl_task *t = data;
34  if (t->cb)
35    t->cb(t->cbdata);
36  return FALSE;
37}
38
39static void _destroy_task(void *data)
40{
41  owl_task *t = data;
42  if (t->destroy_cbdata)
43    t->destroy_cbdata(t->cbdata);
44  g_free(t);
45}
46
47void owl_select_post_task(void (*cb)(void*), void *cbdata, void (*destroy_cbdata)(void*), GMainContext *context)
48{
49  GSource *source = g_idle_source_new();
50  owl_task *t = g_new0(owl_task, 1);
51  t->cb = cb;
52  t->cbdata = cbdata;
53  t->destroy_cbdata = destroy_cbdata;
54  g_source_set_priority(source, G_PRIORITY_DEFAULT);
55  g_source_set_callback(source, _run_task, t, _destroy_task);
56  g_source_attach(source, context);
57  g_source_unref(source);
58}
Note: See TracBrowser for help on using the repository browser.