#include 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);