1 Star 0 Fork 1

swunzg/rtos

forked from erickhuang/rtos 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
os_queue.c 1.12 KB
一键复制 编辑 原始数据 按行查看 历史
erickhuang 提交于 2017-07-15 19:24 . first commit
#include "os.h"
#define QUE_OPT_PRI (1<<0)
#define QUE_OPT_FIFO (1<<1)
Status_t os_que_create(OS_Que *q, U32 opt)
{
U32 sem_opt;
if (q == NULL) {
return RET_FAILURE;
}
if (opt & QUE_OPT_PRI) {
sem_opt = (SEM_OPT_CNT | SEM_OPT_PRI);
}
else if (opt & QUE_OPT_FIFO) {
sem_opt = (SEM_OPT_CNT | SEM_OPT_FIFO);
}
else {
return RET_FAILURE;
}
list_init(&q->head);
return os_sem_create(&q->sem, sem_opt, SEM_EMPTY);
}
Status_t os_que_put(OS_Que *q, LIST *node)
{
if (!q || !node) {
return RET_FAILURE;
}
os_int_lock();
list_insert(&q->head, node);
os_int_unlock();
return os_sem_give(&q->sem);
}
Status_t os_que_get(OS_Que *q, LIST **out, U32 timeout)
{
if (!q || !out) {
return RET_FAILURE;
}
if (os_sem_take(&q->sem, timeout) == RET_SUCCESS) {
os_int_lock();
if (!is_list_empty(&q->head)) {
*out = q->head.next;
list_delete(&q->head.next);
}
else {
*out = NULL;
}
os_int_unlock();
return RET_SUCCESS;
}
else {
*out = NULL;
return RET_FAILURE;
}
}
Status_t os_que_delete(OS_Que *q)
{
if (q == NULL) {
return RET_FAILURE;
}
os_sem_delete(&q->sem);
return RET_SUCCESS;
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/swunzg/rtos.git
git@gitee.com:swunzg/rtos.git
swunzg
rtos
rtos
master

搜索帮助