release-1.10release-1.8release-1.9
Last change
on this file since f4037cf was
84a071f,
checked in by David Benjamin <davidben@mit.edu>, 13 years ago
|
Remove global main_context variable
It's really not necessary. We can pass NULL to g_main_loop_new to use
the default context, and we don't reference the variable anywhere else.
|
-
Property mode set to
100644
|
File size:
1.1 KB
|
Rev | Line | |
---|
[9c7a701] | 1 | #include "owl.h" |
---|
| 2 | |
---|
[2c79eae] | 3 | static GMainLoop *loop = NULL; |
---|
| 4 | |
---|
| 5 | void owl_select_init(void) |
---|
[4f2166b] | 6 | { |
---|
| 7 | } |
---|
| 8 | |
---|
[3ecd78b] | 9 | void owl_select_run_loop(void) |
---|
[4f2166b] | 10 | { |
---|
[84a071f] | 11 | loop = g_main_loop_new(NULL, FALSE); |
---|
[2c79eae] | 12 | g_main_loop_run(loop); |
---|
[4f2166b] | 13 | } |
---|
| 14 | |
---|
[3ecd78b] | 15 | void owl_select_quit_loop(void) |
---|
[4f2166b] | 16 | { |
---|
[2c79eae] | 17 | if (loop) { |
---|
| 18 | g_main_loop_quit(loop); |
---|
[f0781ba] | 19 | g_main_loop_unref(loop); |
---|
[2c79eae] | 20 | loop = NULL; |
---|
[4f2166b] | 21 | } |
---|
| 22 | } |
---|
| 23 | |
---|
[ba12b44] | 24 | typedef struct _owl_task { /*noproto*/ |
---|
| 25 | void (*cb)(void *); |
---|
| 26 | void *cbdata; |
---|
| 27 | void (*destroy_cbdata)(void *); |
---|
| 28 | } owl_task; |
---|
[3a84694] | 29 | |
---|
[ba12b44] | 30 | static gboolean _run_task(gpointer data) |
---|
| 31 | { |
---|
| 32 | owl_task *t = data; |
---|
| 33 | if (t->cb) |
---|
| 34 | t->cb(t->cbdata); |
---|
| 35 | return FALSE; |
---|
[9c7a701] | 36 | } |
---|
[3ecd78b] | 37 | |
---|
[ba12b44] | 38 | static void _destroy_task(void *data) |
---|
[3ecd78b] | 39 | { |
---|
[ba12b44] | 40 | owl_task *t = data; |
---|
| 41 | if (t->destroy_cbdata) |
---|
| 42 | t->destroy_cbdata(t->cbdata); |
---|
| 43 | g_free(t); |
---|
[3ecd78b] | 44 | } |
---|
| 45 | |
---|
[44976fe] | 46 | void owl_select_post_task(void (*cb)(void*), void *cbdata, void (*destroy_cbdata)(void*), GMainContext *context) |
---|
[3ecd78b] | 47 | { |
---|
[ba12b44] | 48 | GSource *source = g_idle_source_new(); |
---|
| 49 | owl_task *t = g_new0(owl_task, 1); |
---|
| 50 | t->cb = cb; |
---|
| 51 | t->cbdata = cbdata; |
---|
| 52 | t->destroy_cbdata = destroy_cbdata; |
---|
| 53 | g_source_set_priority(source, G_PRIORITY_DEFAULT); |
---|
| 54 | g_source_set_callback(source, _run_task, t, _destroy_task); |
---|
| 55 | g_source_attach(source, context); |
---|
| 56 | g_source_unref(source); |
---|
[3ecd78b] | 57 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.