1
0

completion.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. * Completion - A tiny & rapid IPC primitive for resource-constrained scenarios
  16. *
  17. * It's an IPC using one CPU 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_flags(struct rt_completion *completion,
  32. rt_int32_t timeout, int suspend_flag);
  33. void rt_completion_done(struct rt_completion *completion);
  34. rt_err_t rt_completion_wakeup(struct rt_completion *completion);
  35. rt_err_t rt_completion_wakeup_by_errno(struct rt_completion *completion, rt_err_t error);
  36. #endif