1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
#include <glib.h>
typedef struct Engine Engine;
typedef void (* EngineFunc) (gpointer data);
Engine *engine_new (guint n_threads);
void engine_prepend_job (Engine *engine,
EngineFunc func,
gpointer data);
void engine_append_job (Engine *engine,
EngineFunc func,
gpointer data);
void engine_sync (Engine *engine);
void engine_free (Engine *engine);
/* All functions executed within an Context
* are run serialized, ie., two functions from the
* same context never run at the same time.
*
* So if the data those functions operate on (typically
* a client structure) are only ever used by functions queued
* through the context, no locking is necessary.
*
* Note that if more than one thread will be accessing
* a context, locking is necessary. It is not generally
* allowed to call context_* on the same context from more
* than one thread without locking.
*/
typedef struct Context Context;
typedef void (* ContextFdFunc) (Context *context,
int fd);
typedef void (* ContextFdRemovedFunc) (Context *context,
int fd,
gpointer data);
Context *context_new (Engine *engine,
gpointer data);
void context_dispatch (Context *context);
Engine * context_get_engine (Context *context);
gpointer context_get_data (Context *context);
/* fd */
void context_add_fd (Context *contenxt,
int fd);
/* Note that removing an fd from the context also closes it.
* Yeah, that's a little unusual, but the alternative would
* be to add a notification that the fd was no longer in
* any outstanding poll() routines.
*/
void context_remove_fd (Context *context,
int fd);
void context_set_write (Context *contenxt,
int fd,
ContextFdFunc callback);
void context_set_read (Context *context,
int fd,
ContextFdFunc callback);
/* other */
void context_add_idle (Context *context,
EngineFunc func,
gpointer data);
void context_add_timeout (Context *context,
guint timeout_ms,
EngineFunc func,
gpointer data);
void context_add_task (Context *context,
EngineFunc func,
gpointer data);
|