task.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #ifndef CX_ZIVUOS_TASK_H_INCLUDED
  2. #define CX_ZIVUOS_TASK_H_INCLUDED
  3. #include "systypes.h"
  4. /**
  5. * @brief That enum store task type.
  6. *
  7. * Task is container for more than one type of logic.
  8. * - Coroutine is function which run in loop. Could not being scheduled.
  9. * - Oneshot is coroutine which is executed only once.
  10. * - Process is task which could being scheduled.
  11. */
  12. typedef enum zv_task_type_e {
  13. ZV_COROUTINE_TASK,
  14. ZV_PROCESS_TASK,
  15. ZV_ONESHOT_TASK
  16. } zv_task_type_t;
  17. /**
  18. * @brief That enum store task state.
  19. */
  20. typedef enum zv_state_e {
  21. ZV_KILLED,
  22. ZV_RUNNING,
  23. ZV_READY,
  24. ZV_SLEEP
  25. } zv_state_t;
  26. /* That declaration is required for worker. */
  27. struct zv_kernel_s;
  28. /**
  29. * @brief That is worker, which is function for task.
  30. */
  31. typedef zv_state_t (*zv_worker_t) (struct zv_kernel_t *, zv_pid_t);
  32. typedef struct zv_coroutine_s {
  33. zv_worker_t worker;
  34. zv_universal_t param;
  35. } zv_coroutine_t;
  36. typedef struct zv_process_s {
  37. } zv_process_t;
  38. typedef struct zv_oneshot_s {
  39. zv_worker_t worker;
  40. zv_universal_t param;
  41. } zv_oneshot_t;
  42. typedef union zv_task_selector_u {
  43. zv_coroutine_t coroutine;
  44. zv_process_t process;
  45. zv_oneshot_t oneshot;
  46. } zv_task_selector_t;
  47. typedef struct zv_task_s {
  48. zv_pid_t pid;
  49. zv_state_t state;
  50. zv_priority_t priority;
  51. zv_task_type_t type;
  52. zv_task_selector_t selector;
  53. } zv_task_t;
  54. #endif