release-1.10release-1.8release-1.9
|
Last change
on this file since bad4496 was
84a071f,
checked in by David Benjamin <davidben@mit.edu>, 14 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
|
| Line | |
|---|
| 1 | #include "owl.h" |
|---|
| 2 | |
|---|
| 3 | static GMainLoop *loop = NULL; |
|---|
| 4 | |
|---|
| 5 | void owl_select_init(void) |
|---|
| 6 | { |
|---|
| 7 | } |
|---|
| 8 | |
|---|
| 9 | void owl_select_run_loop(void) |
|---|
| 10 | { |
|---|
| 11 | loop = g_main_loop_new(NULL, FALSE); |
|---|
| 12 | g_main_loop_run(loop); |
|---|
| 13 | } |
|---|
| 14 | |
|---|
| 15 | void owl_select_quit_loop(void) |
|---|
| 16 | { |
|---|
| 17 | if (loop) { |
|---|
| 18 | g_main_loop_quit(loop); |
|---|
| 19 | g_main_loop_unref(loop); |
|---|
| 20 | loop = NULL; |
|---|
| 21 | } |
|---|
| 22 | } |
|---|
| 23 | |
|---|
| 24 | typedef struct _owl_task { /*noproto*/ |
|---|
| 25 | void (*cb)(void *); |
|---|
| 26 | void *cbdata; |
|---|
| 27 | void (*destroy_cbdata)(void *); |
|---|
| 28 | } owl_task; |
|---|
| 29 | |
|---|
| 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; |
|---|
| 36 | } |
|---|
| 37 | |
|---|
| 38 | static void _destroy_task(void *data) |
|---|
| 39 | { |
|---|
| 40 | owl_task *t = data; |
|---|
| 41 | if (t->destroy_cbdata) |
|---|
| 42 | t->destroy_cbdata(t->cbdata); |
|---|
| 43 | g_free(t); |
|---|
| 44 | } |
|---|
| 45 | |
|---|
| 46 | void owl_select_post_task(void (*cb)(void*), void *cbdata, void (*destroy_cbdata)(void*), GMainContext *context) |
|---|
| 47 | { |
|---|
| 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); |
|---|
| 57 | } |
|---|
Note: See
TracBrowser
for help on using the repository browser.