completion.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. * Copyright (c) 2006-2023, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2024-04-28 Shell Add new wait_flags() & wakeup_by_errno() API
  9. * 2024-10-24 yekai Add C++ support
  10. */
  11. #ifndef COMPLETION_H_
  12. #define COMPLETION_H_
  13. #include <rtdef.h>
  14. #include <rtconfig.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. #ifdef __cplusplus
  30. extern "C" {
  31. #endif
  32. void rt_completion_init(struct rt_completion *completion);
  33. rt_err_t rt_completion_wait(struct rt_completion *completion,
  34. rt_int32_t timeout);
  35. rt_err_t rt_completion_wait_noisr(struct rt_completion *completion,
  36. rt_int32_t timeout);
  37. rt_err_t rt_completion_wait_flags(struct rt_completion *completion,
  38. rt_int32_t timeout, int suspend_flag);
  39. rt_err_t rt_completion_wait_flags_noisr(struct rt_completion *completion,
  40. rt_int32_t timeout, int suspend_flag);
  41. void rt_completion_done(struct rt_completion *completion);
  42. rt_err_t rt_completion_wakeup(struct rt_completion *completion);
  43. rt_err_t rt_completion_wakeup_by_errno(struct rt_completion *completion, rt_err_t error);
  44. #ifdef __cplusplus
  45. }
  46. #endif
  47. #endif