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