completion.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. */
  10. #ifndef COMPLETION_H_
  11. #define COMPLETION_H_
  12. #include <rtdef.h>
  13. #include <rtconfig.h>
  14. /**
  15. * RT-Completion - A Tiny(resource-constrained) & Rapid(lockless) IPC Primitive
  16. *
  17. * It's an IPC using one pointer word with the encoding:
  18. *
  19. * BIT | MAX-1 ----------------- 1 | 0 |
  20. * CONTENT | suspended_thread & ~1 | completed flag |
  21. */
  22. struct rt_completion
  23. {
  24. /* suspended thread, and completed flag */
  25. rt_atomic_t susp_thread_n_flag;
  26. };
  27. #define RT_COMPLETION_INIT(comp) {0}
  28. void rt_completion_init(struct rt_completion *completion);
  29. rt_err_t rt_completion_wait(struct rt_completion *completion,
  30. rt_int32_t timeout);
  31. rt_err_t rt_completion_wait_noisr(struct rt_completion *completion,
  32. rt_int32_t timeout);
  33. rt_err_t rt_completion_wait_flags(struct rt_completion *completion,
  34. rt_int32_t timeout, int suspend_flag);
  35. rt_err_t rt_completion_wait_flags_noisr(struct rt_completion *completion,
  36. rt_int32_t timeout, int suspend_flag);
  37. void rt_completion_done(struct rt_completion *completion);
  38. rt_err_t rt_completion_wakeup(struct rt_completion *completion);
  39. rt_err_t rt_completion_wakeup_by_errno(struct rt_completion *completion, rt_err_t error);
  40. #endif