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 14 #include <rtdef.h> 15 #include <rtconfig.h> 16 17 /** 18 * RT-Completion - A Tiny(resource-constrained) & Rapid(lockless) IPC Primitive 19 * 20 * It's an IPC using one pointer word with the encoding: 21 * 22 * BIT | MAX-1 ----------------- 1 | 0 | 23 * CONTENT | suspended_thread & ~1 | completed flag | 24 */ 25 26 struct rt_completion 27 { 28 /* suspended thread, and completed flag */ 29 rt_atomic_t susp_thread_n_flag; 30 }; 31 32 #define RT_COMPLETION_INIT(comp) {0} 33 34 #ifdef __cplusplus 35 extern "C" { 36 #endif 37 38 void rt_completion_init(struct rt_completion *completion); 39 rt_err_t rt_completion_wait(struct rt_completion *completion, 40 rt_int32_t timeout); 41 rt_err_t rt_completion_wait_noisr(struct rt_completion *completion, 42 rt_int32_t timeout); 43 rt_err_t rt_completion_wait_flags(struct rt_completion *completion, 44 rt_int32_t timeout, int suspend_flag); 45 rt_err_t rt_completion_wait_flags_noisr(struct rt_completion *completion, 46 rt_int32_t timeout, int suspend_flag); 47 void rt_completion_done(struct rt_completion *completion); 48 rt_err_t rt_completion_wakeup(struct rt_completion *completion); 49 rt_err_t rt_completion_wakeup_by_errno(struct rt_completion *completion, rt_err_t error); 50 51 #ifdef __cplusplus 52 } 53 #endif 54 55 #endif 56