]> git.ozlabs.org Git - ccan/blob - ccan/antithread/antithread.h
Implementation of auto-depends, based on Idris's start.
[ccan] / ccan / antithread / antithread.h
1 #ifndef ANTITHREAD_H
2 #define ANTITHREAD_H
3 #include <ccan/typesafe_cb/typesafe_cb.h>
4
5 struct at_pool;
6 struct athread;
7
8 /* Operations for the parent. */
9
10 /* Create a new sharable pool. */
11 struct at_pool *at_pool(unsigned long size);
12
13 /* Talloc off this to allocate from within the pool. */
14 const void *at_pool_ctx(struct at_pool *atp);
15
16 /* Creating an antithread via fork().  Returned athread is child of pool. */
17 #define at_run(pool, fn, arg)                                           \
18         _at_run(pool,                                                   \
19                 typesafe_cb_preargs(void *, (fn), (arg), struct at_pool *), \
20                 (arg))
21
22 /* Fork and execvp, with added arguments for child to grab.
23  * Returned athread is child of pool. */
24 struct athread *at_spawn(struct at_pool *pool, void *arg, char *cmdline[]);
25
26 /* The fd to poll on */
27 int at_fd(struct athread *at);
28
29 /* What's the antithread saying?  Blocks if fd not ready. */
30 void *at_read(struct athread *at);
31
32 /* Say something to a child (async). */
33 void at_tell(struct athread *at, const void *status);
34
35 /* Operations for the children */
36 /* For child to grab arguments from command line (removes them) */
37 struct at_pool *at_get_pool(int *argc, char *argv[], void **arg);
38
39 /* Say something to our parent (async). */
40 void at_tell_parent(struct at_pool *pool, const void *status);
41
42 /* What's the parent saying?  Blocks if fd not ready. */
43 void *at_read_parent(struct at_pool *pool);
44
45 /* The fd to poll on */
46 int at_parent_fd(struct at_pool *pool);
47
48 /* Locking: any talloc pointer. */
49 void at_lock(void *obj);
50 void at_unlock(void *obj);
51
52 void at_lock_all(struct at_pool *pool);
53 void at_unlock_all(struct at_pool *pool);
54
55 /* Internal function */
56 struct athread *_at_run(struct at_pool *pool,
57                         void *(*fn)(struct at_pool *, void *arg),
58                         void *arg);
59
60 #endif /* ANTITHREAD_H */