release-1.10
Last change
on this file since 565a43c 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
|
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_slice_free(owl_task, 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_slice_new0(owl_task); |
---|
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.