antithread.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. struct at_pool;
  6. struct athread;
  7. /* Operations for the parent. */
  8. /* Create a new sharable pool. */
  9. struct at_pool *at_pool(unsigned long size);
  10. /* Talloc off this to allocate from within the pool. */
  11. const void *at_pool_ctx(struct at_pool *atp);
  12. /* Creating an antithread via fork(). Returned athread is child of pool. */
  13. #define at_run(pool, fn, arg) \
  14. _at_run(pool, \
  15. typesafe_cb_preargs(void *, void *, (fn), (arg), struct at_pool *), \
  16. (arg))
  17. /* Fork and execvp, with added arguments for child to grab.
  18. * Returned athread is child of pool. */
  19. struct athread *at_spawn(struct at_pool *pool, void *arg, char *cmdline[]);
  20. /* The fd to poll on */
  21. int at_fd(struct athread *at);
  22. /* What's the antithread saying? Blocks if fd not ready. */
  23. void *at_read(struct athread *at);
  24. /* Say something to a child (async). */
  25. void at_tell(struct athread *at, const void *status);
  26. /* Operations for the children */
  27. /* For child to grab arguments from command line (removes them) */
  28. struct at_pool *at_get_pool(int *argc, char *argv[], void **arg);
  29. /* Say something to our parent (async). */
  30. void at_tell_parent(struct at_pool *pool, const void *status);
  31. /* What's the parent saying? Blocks if fd not ready. */
  32. void *at_read_parent(struct at_pool *pool);
  33. /* The fd to poll on */
  34. int at_parent_fd(struct at_pool *pool);
  35. /* Locking: any talloc pointer. */
  36. void at_lock(void *obj);
  37. void at_unlock(void *obj);
  38. void at_lock_all(struct at_pool *pool);
  39. void at_unlock_all(struct at_pool *pool);
  40. /* Internal function */
  41. struct athread *_at_run(struct at_pool *pool,
  42. void *(*fn)(struct at_pool *, void *arg),
  43. void *arg);
  44. #endif /* ANTITHREAD_H */