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
|
/* Licensed under GPLv3+ - see LICENSE file for details */
#ifndef ANTITHREAD_H
#define ANTITHREAD_H
#include <ccan/typesafe_cb/typesafe_cb.h>
struct at_pool;
struct athread;
/* Operations for the parent. */
/* Create a new sharable pool. */
struct at_pool *at_pool(unsigned long size);
/* Talloc off this to allocate from within the pool. */
const void *at_pool_ctx(struct at_pool *atp);
/* Creating an antithread via fork(). Returned athread is child of pool. */
#define at_run(pool, fn, arg) \
_at_run(pool, \
typesafe_cb_preargs(void *, void *, (fn), (arg), struct at_pool *), \
(arg))
/* Fork and execvp, with added arguments for child to grab.
* Returned athread is child of pool. */
struct athread *at_spawn(struct at_pool *pool, void *arg, char *cmdline[]);
/* The fd to poll on */
int at_fd(struct athread *at);
/* What's the antithread saying? Blocks if fd not ready. */
void *at_read(struct athread *at);
/* Say something to a child (async). */
void at_tell(struct athread *at, const void *status);
/* Operations for the children */
/* For child to grab arguments from command line (removes them) */
struct at_pool *at_get_pool(int *argc, char *argv[], void **arg);
/* Say something to our parent (async). */
void at_tell_parent(struct at_pool *pool, const void *status);
/* What's the parent saying? Blocks if fd not ready. */
void *at_read_parent(struct at_pool *pool);
/* The fd to poll on */
int at_parent_fd(struct at_pool *pool);
/* Locking: any talloc pointer. */
void at_lock(void *obj);
void at_unlock(void *obj);
void at_lock_all(struct at_pool *pool);
void at_unlock_all(struct at_pool *pool);
/* Internal function */
struct athread *_at_run(struct at_pool *pool,
void *(*fn)(struct at_pool *, void *arg),
void *arg);
#endif /* ANTITHREAD_H */
|