2018-10-14 19:37:18 +08:00
|
|
|
/*
|
2023-04-18 10:26:23 +08:00
|
|
|
* Copyright (c) 2006-2023, RT-Thread Development Team
|
2018-10-14 19:37:18 +08:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*
|
|
|
|
* Change Logs:
|
|
|
|
* Date Author Notes
|
2024-05-08 09:25:57 +08:00
|
|
|
* 2024-04-28 Shell Add new wait_flags() & wakeup_by_errno() API
|
2018-10-14 19:37:18 +08:00
|
|
|
*/
|
2017-10-15 22:56:46 +08:00
|
|
|
#ifndef COMPLETION_H_
|
|
|
|
#define COMPLETION_H_
|
|
|
|
|
2023-07-29 06:26:51 +08:00
|
|
|
#include <rtdef.h>
|
|
|
|
#include <rtconfig.h>
|
2017-10-15 22:56:46 +08:00
|
|
|
|
|
|
|
/**
|
2024-05-08 09:25:57 +08:00
|
|
|
* Completion - A tiny & rapid IPC primitive for resource-constrained scenarios
|
2024-02-23 17:49:15 +08:00
|
|
|
*
|
|
|
|
* It's an IPC using one CPU word with the encoding:
|
|
|
|
*
|
|
|
|
* BIT | MAX-1 ----------------- 1 | 0 |
|
|
|
|
* CONTENT | suspended_thread & ~1 | completed flag |
|
2017-10-15 22:56:46 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
struct rt_completion
|
|
|
|
{
|
2024-02-23 17:49:15 +08:00
|
|
|
/* suspended thread, and completed flag */
|
2024-05-08 09:25:57 +08:00
|
|
|
rt_atomic_t susp_thread_n_flag;
|
2017-10-15 22:56:46 +08:00
|
|
|
};
|
|
|
|
|
2024-02-23 17:49:15 +08:00
|
|
|
#define RT_COMPLETION_INIT(comp) {0}
|
|
|
|
|
2017-10-15 22:56:46 +08:00
|
|
|
void rt_completion_init(struct rt_completion *completion);
|
|
|
|
rt_err_t rt_completion_wait(struct rt_completion *completion,
|
|
|
|
rt_int32_t timeout);
|
2024-05-08 09:25:57 +08:00
|
|
|
rt_err_t rt_completion_wait_flags(struct rt_completion *completion,
|
|
|
|
rt_int32_t timeout, int suspend_flag);
|
2017-10-15 22:56:46 +08:00
|
|
|
void rt_completion_done(struct rt_completion *completion);
|
2024-03-28 23:42:56 +08:00
|
|
|
rt_err_t rt_completion_wakeup(struct rt_completion *completion);
|
2024-05-08 09:25:57 +08:00
|
|
|
rt_err_t rt_completion_wakeup_by_errno(struct rt_completion *completion, rt_err_t error);
|
2017-10-15 22:56:46 +08:00
|
|
|
#endif
|