release-1.10
Last change
on this file since 1bd5aa9 was
7dcef03,
checked in by Anders Kaseorg <andersk@mit.edu>, 11 years ago
|
Use the Glib slice allocator for fixed-size objects
The slice allocator, available since GLib 2.10, is more
space-efficient than [g_]malloc. Since BarnOwl is obviously at the
leading edge of space-efficient technology, this seems like a natural
fit. Use it for every fixed-size object except
owl_viewwin_search_data (which would need an extra destroy_cbdata
function to g_slice_free it).
Signed-off-by: Anders Kaseorg <andersk@mit.edu>
|
-
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); |
---|
[7dcef03] | 43 | g_slice_free(owl_task, 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(); |
---|
[7dcef03] | 49 | owl_task *t = g_slice_new0(owl_task); |
---|
[ba12b44] | 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.