thread.h 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. /*
  2. * thread.h
  3. *
  4. * Cooperative multitasking.
  5. *
  6. * Written & released by Keir Fraser <keir.xen@gmail.com> and Eric Anderson
  7. * <ejona86@gmail.com>
  8. *
  9. * This is free and unencumbered software released into the public domain.
  10. * See the file COPYING for more details, or visit <http://unlicense.org>.
  11. */
  12. struct thread {
  13. /* Internal bookkeeping */
  14. bool_t exited;
  15. };
  16. /* Initialize a thread and queue it for execution. 'thread' must remain
  17. * allocated for the lifetime of the thread. */
  18. void thread_start(struct thread *thread, uint32_t *stack, void (*func)(void*), void* arg);
  19. /* Yield execution to allow other threads to run. */
  20. void thread_yield(void);
  21. /* Returns true if provided thread has exited. A thread cannot be joined
  22. * multiple times, unless it is started anew. */
  23. bool_t thread_tryjoin(struct thread *thread);
  24. /* Continuously yields until provided thread has exited. A thread cannot be
  25. * joined multiple times, unless it is started anew. */
  26. void thread_join(struct thread *thread);
  27. /* Reinitializes threading subsystem to its initial state, throwing away all
  28. * threads but the current. */
  29. void thread_reset(void);