completion.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /**
  2. * RT-Thread RuiChing
  3. *
  4. * COPYRIGHT (C) 2024-2025 Shanghai Real-Thread Electronic Technology Co., Ltd.
  5. * All rights reserved.
  6. *
  7. * The license and distribution terms for this file may be
  8. * found in the file LICENSE in this distribution.
  9. */
  10. #ifndef __COMPLETION_H_
  11. #define __COMPLETION_H_
  12. #include <kpi.h>
  13. #include <rtconfig.h>
  14. #include <rtdef.h>
  15. /**
  16. * RT-Completion - A Tiny(resource-constrained) & Rapid(lockless) IPC Primitive
  17. *
  18. * It's an IPC using one pointer word with the encoding:
  19. *
  20. * BIT | MAX-1 ----------------- 1 | 0 |
  21. * CONTENT | suspended_thread & ~1 | completed flag |
  22. */
  23. struct rt_completion
  24. {
  25. /* suspended thread, and completed flag */
  26. rt_atomic_t susp_thread_n_flag;
  27. };
  28. #define RT_COMPLETION_INIT(comp) { 0 }
  29. typedef void (*__kpi_rt_completion_init)(struct rt_completion *completion);
  30. typedef rt_err_t (*__kpi_rt_completion_wait)(
  31. struct rt_completion *completion, rt_int32_t timeout);
  32. typedef rt_err_t (*__kpi_rt_completion_wait_noisr)(
  33. struct rt_completion *completion, rt_int32_t timeout);
  34. typedef rt_err_t (*__kpi_rt_completion_wait_flags)(
  35. struct rt_completion *completion, rt_int32_t timeout, int suspend_flag);
  36. typedef rt_err_t (*__kpi_rt_completion_wait_flags_noisr)(
  37. struct rt_completion *completion, rt_int32_t timeout, int suspend_flag);
  38. typedef void (*__kpi_rt_completion_done)(struct rt_completion *completion);
  39. typedef rt_err_t (*__kpi_rt_completion_wakeup)(
  40. struct rt_completion *completion);
  41. typedef rt_err_t (*__kpi_rt_completion_wakeup_by_errno)(
  42. struct rt_completion *completion, rt_err_t error);
  43. KPI_EXTERN(rt_completion_init);
  44. KPI_EXTERN(rt_completion_wait);
  45. KPI_EXTERN(rt_completion_wait_noisr);
  46. KPI_EXTERN(rt_completion_wait_flags);
  47. KPI_EXTERN(rt_completion_wait_flags_noisr);
  48. KPI_EXTERN(rt_completion_done);
  49. KPI_EXTERN(rt_completion_wakeup);
  50. KPI_EXTERN(rt_completion_wakeup_by_errno);
  51. #endif /* __COMPLETION_H_ */