Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
2301_76519099
rt-thread
提交
19aa36e8
R
rt-thread
项目概览
2301_76519099
/
rt-thread
与 Fork 源项目一致
Fork自
RT-Thread / rt-thread
通知
3
Star
1
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rt-thread
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
19aa36e8
编写于
10月 17, 2017
作者:
B
bernard
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[DeviceDrivers] Add sync mode in work queue.
上级
6101d1e8
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
62 addition
and
0 deletion
+62
-0
components/drivers/include/ipc/workqueue.h
components/drivers/include/ipc/workqueue.h
+3
-0
components/drivers/src/workqueue.c
components/drivers/src/workqueue.c
+59
-0
未找到文件。
components/drivers/include/ipc/workqueue.h
浏览文件 @
19aa36e8
...
...
@@ -8,6 +8,8 @@ struct rt_workqueue
{
rt_list_t
work_list
;
struct
rt_work
*
work_current
;
/* current work */
struct
rt_semaphore
sem
;
rt_thread_t
work_thread
;
};
...
...
@@ -27,6 +29,7 @@ struct rt_workqueue *rt_workqueue_create(const char* name, rt_uint16_t stack_siz
rt_err_t
rt_workqueue_destroy
(
struct
rt_workqueue
*
queue
);
rt_err_t
rt_workqueue_dowork
(
struct
rt_workqueue
*
queue
,
struct
rt_work
*
work
);
rt_err_t
rt_workqueue_cancel_work
(
struct
rt_workqueue
*
queue
,
struct
rt_work
*
work
);
rt_err_t
rt_workqueue_cancel_work_sync
(
struct
rt_workqueue
*
queue
,
struct
rt_work
*
work
);
rt_inline
void
rt_work_init
(
struct
rt_work
*
work
,
void
(
*
work_func
)(
struct
rt_work
*
work
,
void
*
work_data
),
void
*
work_data
)
...
...
components/drivers/src/workqueue.c
浏览文件 @
19aa36e8
...
...
@@ -27,6 +27,37 @@
#include <rtdevice.h>
#ifdef RT_USING_HEAP
rt_inline
rt_err_t
_workqueue_work_completion
(
struct
rt_workqueue
*
queue
)
{
rt_err_t
result
;
rt_enter_critical
();
while
(
1
)
{
/* try to take condition semaphore */
result
=
rt_sem_trytake
(
&
(
queue
->
sem
));
if
(
result
==
-
RT_ETIMEOUT
)
{
/* it's timeout, release this semaphore */
rt_sem_release
(
&
(
queue
->
sem
));
}
else
if
(
result
==
RT_EOK
)
{
/* keep the sem value = 0 */
result
=
RT_EOK
;
break
;
}
else
{
result
=
-
RT_ERROR
;
break
;
}
}
rt_exit_critical
();
return
result
;
}
static
void
_workqueue_thread_entry
(
void
*
parameter
)
{
rt_base_t
level
;
...
...
@@ -58,6 +89,9 @@ static void _workqueue_thread_entry(void* parameter)
/* clean current work */
queue
->
work_current
=
RT_NULL
;
rt_hw_interrupt_enable
(
level
);
/* ack work completion */
_workqueue_work_completion
(
queue
);
}
}
...
...
@@ -71,6 +105,7 @@ struct rt_workqueue *rt_workqueue_create(const char* name, rt_uint16_t stack_siz
/* initialize work list */
rt_list_init
(
&
(
queue
->
work_list
));
queue
->
work_current
=
RT_NULL
;
rt_sem_init
(
&
(
queue
->
sem
),
"wqueue"
,
0
,
RT_IPC_FLAG_FIFO
);
/* create the work thread */
queue
->
work_thread
=
rt_thread_create
(
name
,
_workqueue_thread_entry
,
queue
,
stack_size
,
priority
,
10
);
...
...
@@ -174,6 +209,30 @@ rt_err_t rt_workqueue_cancel_work(struct rt_workqueue* queue, struct rt_work* wo
return
RT_EOK
;
}
rt_err_t
rt_workqueue_cancel_work_sync
(
struct
rt_workqueue
*
queue
,
struct
rt_work
*
work
)
{
rt_base_t
level
;
RT_ASSERT
(
queue
!=
RT_NULL
);
RT_ASSERT
(
work
!=
RT_NULL
);
level
=
rt_hw_interrupt_disable
();
if
(
queue
->
work_current
==
work
)
/* it's current work in the queue */
{
rt_uint32_t
recv
;
/* wait for work completion */
rt_sem_take
(
&
(
queue
->
sem
),
RT_WAITING_FOREVER
);
}
else
{
rt_list_remove
(
&
(
work
->
list
));
}
rt_hw_interrupt_enable
(
level
);
return
RT_EOK
;
}
rt_err_t
rt_workqueue_cancel_all_work
(
struct
rt_workqueue
*
queue
)
{
struct
rt_list_node
*
node
,
*
next
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录