Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
rt-thread
提交
e5c8e160
R
rt-thread
项目概览
BaiXuePrincess
/
rt-thread
与 Fork 源项目一致
Fork自
RT-Thread / rt-thread
通知
1
Star
0
Fork
0
代码
文件
提交
分支
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看板
提交
e5c8e160
编写于
8月 20, 2014
作者:
B
Bernard Xiong
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #316 from grissiom/fix-mempool
kernel: mempool: fix race condition in rt_mp_alloc
上级
a55fd4b9
be0c0481
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
49 addition
and
48 deletion
+49
-48
src/mempool.c
src/mempool.c
+49
-48
未找到文件。
src/mempool.c
浏览文件 @
e5c8e160
...
...
@@ -323,23 +323,15 @@ void *rt_mp_alloc(rt_mp_t mp, rt_int32_t time)
rt_uint8_t
*
block_ptr
;
register
rt_base_t
level
;
struct
rt_thread
*
thread
;
rt_uint32_t
before_sleep
=
0
;
/* get current thread */
thread
=
rt_thread_self
();
/* disable interrupt */
level
=
rt_hw_interrupt_disable
();
if
(
mp
->
block_free_count
)
{
/* memory block is available. decrease the free block counter */
mp
->
block_free_count
--
;
/* get block from block list */
block_ptr
=
mp
->
block_list
;
mp
->
block_list
=
*
(
rt_uint8_t
**
)
block_ptr
;
/* point to memory pool */
*
(
rt_uint8_t
**
)
block_ptr
=
(
rt_uint8_t
*
)
mp
;
}
else
while
(
mp
->
block_free_count
==
0
)
{
/* memory block is unavailable. */
if
(
time
==
0
)
...
...
@@ -347,54 +339,63 @@ void *rt_mp_alloc(rt_mp_t mp, rt_int32_t time)
/* enable interrupt */
rt_hw_interrupt_enable
(
level
);
rt_set_errno
(
-
RT_ETIMEOUT
);
return
RT_NULL
;
}
else
{
RT_DEBUG_NOT_IN_INTERRUPT
;
/* get current thread */
thread
=
rt_thread_self
();
RT_DEBUG_NOT_IN_INTERRUPT
;
thread
->
error
=
RT_EOK
;
thread
->
error
=
RT_EOK
;
/* need suspend thread */
rt_thread_suspend
(
thread
);
rt_list_insert_after
(
&
(
mp
->
suspend_thread
),
&
(
thread
->
tlist
));
mp
->
suspend_thread_count
++
;
/* need suspend thread */
rt_thread_suspend
(
thread
);
rt_list_insert_after
(
&
(
mp
->
suspend_thread
),
&
(
thread
->
tlist
));
mp
->
suspend_thread_count
++
;
if
(
time
>
0
)
{
/* init thread timer and start it */
rt_timer_control
(
&
(
thread
->
thread_timer
),
RT_TIMER_CTRL_SET_TIME
,
&
time
);
rt_timer_start
(
&
(
thread
->
thread_timer
));
}
if
(
time
>
0
)
{
/* get the start tick of timer */
before_sleep
=
rt_tick_get
();
/* init thread timer and start it */
rt_timer_control
(
&
(
thread
->
thread_timer
),
RT_TIMER_CTRL_SET_TIME
,
&
time
);
rt_timer_start
(
&
(
thread
->
thread_timer
));
}
/* enable interrupt */
rt_hw_interrupt_enable
(
level
);
/* enable interrupt */
rt_hw_interrupt_enable
(
level
);
/* do a schedule */
rt_schedule
();
/* do a schedule */
r
t_schedule
()
;
if
(
thread
->
error
!=
RT_EOK
)
r
eturn
RT_NULL
;
if
(
thread
->
error
!=
RT_EOK
)
return
RT_NULL
;
if
(
time
>
0
)
{
time
-=
rt_tick_get
()
-
before_sleep
;
if
(
time
<
0
)
time
=
0
;
}
/* disable interrupt */
level
=
rt_hw_interrupt_disable
();
}
/* disable interrupt
*/
level
=
rt_hw_interrupt_disable
()
;
/* memory block is available. decrease the free block counter
*/
mp
->
block_free_count
--
;
/* decrease free block */
mp
->
block_free_count
--
;
/* get block from block list */
block_ptr
=
mp
->
block_list
;
RT_ASSERT
(
block_ptr
!=
RT_NULL
);
/* get block from block list */
block_ptr
=
mp
->
block_list
;
mp
->
block_list
=
*
(
rt_uint8_t
**
)
block_ptr
;
/* Setup the next free node. */
mp
->
block_list
=
*
(
rt_uint8_t
**
)
block_ptr
;
/* point to memory pool */
*
(
rt_uint8_t
**
)
block_ptr
=
(
rt_uint8_t
*
)
mp
;
}
}
/* point to memory pool */
*
(
rt_uint8_t
**
)
block_ptr
=
(
rt_uint8_t
*
)
mp
;
/* enable interrupt */
rt_hw_interrupt_enable
(
level
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录