Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
码匠许师傅
rt-thread
提交
3638e512
R
rt-thread
项目概览
码匠许师傅
/
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
3638e512
编写于
5月 12, 2019
作者:
B
Bernard Xiong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[pthreads] The fields definition are more like those of newlib/glibc.
上级
6e981106
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
38 addition
and
34 deletion
+38
-34
components/libc/pthreads/pthread.c
components/libc/pthreads/pthread.c
+10
-10
components/libc/pthreads/pthread.h
components/libc/pthreads/pthread.h
+12
-11
components/libc/pthreads/pthread_attr.c
components/libc/pthreads/pthread_attr.c
+16
-13
未找到文件。
components/libc/pthreads/pthread.c
浏览文件 @
3638e512
...
...
@@ -34,7 +34,7 @@ static void _pthread_destroy(_pthread_data_t *ptd)
rt_sem_delete
(
ptd
->
joinable_sem
);
/* release thread resource */
if
(
ptd
->
attr
.
stack
_base
==
RT_NULL
)
if
(
ptd
->
attr
.
stack
addr
==
RT_NULL
)
{
/* release thread allocated stack */
rt_free
(
ptd
->
tid
->
stack_addr
);
...
...
@@ -119,13 +119,13 @@ int pthread_create(pthread_t *tid,
}
rt_snprintf
(
name
,
sizeof
(
name
),
"pth%02d"
,
pthread_number
++
);
if
(
ptd
->
attr
.
stack
_base
==
0
)
if
(
ptd
->
attr
.
stack
addr
==
0
)
{
stack
=
(
void
*
)
rt_malloc
(
ptd
->
attr
.
stack
_
size
);
stack
=
(
void
*
)
rt_malloc
(
ptd
->
attr
.
stacksize
);
}
else
{
stack
=
(
void
*
)(
ptd
->
attr
.
stack
_base
);
stack
=
(
void
*
)(
ptd
->
attr
.
stack
addr
);
}
if
(
stack
==
RT_NULL
)
...
...
@@ -139,7 +139,7 @@ int pthread_create(pthread_t *tid,
ptd
->
tid
=
(
rt_thread_t
)
rt_malloc
(
sizeof
(
struct
rt_thread
));
if
(
ptd
->
tid
==
RT_NULL
)
{
if
(
ptd
->
attr
.
stack
_base
==
0
)
if
(
ptd
->
attr
.
stack
addr
==
0
)
rt_free
(
stack
);
rt_free
(
ptd
);
...
...
@@ -151,7 +151,7 @@ int pthread_create(pthread_t *tid,
ptd
->
joinable_sem
=
rt_sem_create
(
name
,
0
,
RT_IPC_FLAG_FIFO
);
if
(
ptd
->
joinable_sem
==
RT_NULL
)
{
if
(
ptd
->
attr
.
stack
_base
!=
0
)
if
(
ptd
->
attr
.
stack
addr
!=
0
)
rt_free
(
stack
);
rt_free
(
ptd
);
...
...
@@ -169,10 +169,10 @@ int pthread_create(pthread_t *tid,
/* initial this pthread to system */
if
(
rt_thread_init
(
ptd
->
tid
,
name
,
pthread_entry_stub
,
ptd
,
stack
,
ptd
->
attr
.
stack
_
size
,
ptd
->
attr
.
priority
,
5
)
!=
RT_EOK
)
stack
,
ptd
->
attr
.
stacksize
,
ptd
->
attr
.
schedparam
.
sched_
priority
,
5
)
!=
RT_EOK
)
{
if
(
ptd
->
attr
.
stack
_base
==
0
)
if
(
ptd
->
attr
.
stack
addr
==
0
)
rt_free
(
stack
);
if
(
ptd
->
joinable_sem
!=
RT_NULL
)
rt_sem_delete
(
ptd
->
joinable_sem
);
...
...
@@ -195,7 +195,7 @@ int pthread_create(pthread_t *tid,
/* start thread failed */
rt_thread_detach
(
ptd
->
tid
);
if
(
ptd
->
attr
.
stack
_base
==
0
)
if
(
ptd
->
attr
.
stack
addr
==
0
)
rt_free
(
stack
);
if
(
ptd
->
joinable_sem
!=
RT_NULL
)
rt_sem_delete
(
ptd
->
joinable_sem
);
...
...
components/libc/pthreads/pthread.h
浏览文件 @
3638e512
...
...
@@ -76,15 +76,21 @@ enum
#define PTHREAD_SCOPE_PROCESS 0
#define PTHREAD_SCOPE_SYSTEM 1
struct
sched_param
{
int
sched_priority
;
};
struct
pthread_attr
{
void
*
stack_base
;
rt_uint32_t
stack_size
;
/* stack size of thread */
void
*
stackaddr
;
/* stack address of thread */
int
stacksize
;
/* stack size of thread */
int
inheritsched
;
/* Inherit parent prio/policy */
int
schedpolicy
;
/* scheduler policy */
struct
sched_param
schedparam
;
/* sched parameter */
rt_uint8_t
priority
;
/* priority of thread */
rt_uint8_t
detachstate
;
/* detach state */
rt_uint8_t
policy
;
/* scheduler policy */
rt_uint8_t
inheritsched
;
/* Inherit parent prio/policy */
int
detachstate
;
/* detach state */
};
typedef
struct
pthread_attr
pthread_attr_t
;
...
...
@@ -131,11 +137,6 @@ struct pthread_barrier
};
typedef
struct
pthread_barrier
pthread_barrier_t
;
struct
sched_param
{
int
sched_priority
;
};
/* pthread thread interface */
int
pthread_attr_destroy
(
pthread_attr_t
*
attr
);
int
pthread_attr_init
(
pthread_attr_t
*
attr
);
...
...
components/libc/pthreads/pthread_attr.c
浏览文件 @
3638e512
...
...
@@ -20,10 +20,13 @@ const pthread_attr_t pthread_default_attr =
{
0
,
/* stack base */
DEFAULT_STACK_SIZE
,
/* stack size */
DEFAULT_PRIORITY
,
/* priority */
PTHREAD_
CREATE_JOINABLE
,
/* detach state
*/
PTHREAD_
INHERIT_SCHED
,
/* Inherit parent prio/policy
*/
SCHED_FIFO
,
/* scheduler policy */
PTHREAD_INHERIT_SCHED
/* Inherit parent prio/policy */
{
DEFAULT_PRIORITY
,
/* scheduler priority */
},
PTHREAD_CREATE_JOINABLE
,
/* detach state */
};
int
pthread_attr_init
(
pthread_attr_t
*
attr
)
...
...
@@ -73,7 +76,7 @@ int pthread_attr_setschedpolicy(pthread_attr_t *attr, int policy)
{
RT_ASSERT
(
attr
!=
RT_NULL
);
attr
->
policy
=
policy
;
attr
->
sched
policy
=
policy
;
return
0
;
}
...
...
@@ -83,7 +86,7 @@ int pthread_attr_getschedpolicy(pthread_attr_t const *attr, int *policy)
{
RT_ASSERT
(
attr
!=
RT_NULL
);
*
policy
=
(
int
)
attr
->
policy
;
*
policy
=
(
int
)
attr
->
sched
policy
;
return
0
;
}
...
...
@@ -95,7 +98,7 @@ int pthread_attr_setschedparam(pthread_attr_t *attr,
RT_ASSERT
(
attr
!=
RT_NULL
);
RT_ASSERT
(
param
!=
RT_NULL
);
attr
->
priority
=
param
->
sched_priority
;
attr
->
schedparam
.
sched_
priority
=
param
->
sched_priority
;
return
0
;
}
...
...
@@ -107,7 +110,7 @@ int pthread_attr_getschedparam(pthread_attr_t const *attr,
RT_ASSERT
(
attr
!=
RT_NULL
);
RT_ASSERT
(
param
!=
RT_NULL
);
param
->
sched_priority
=
attr
->
priority
;
param
->
sched_priority
=
attr
->
schedparam
.
sched_
priority
;
return
0
;
}
...
...
@@ -117,7 +120,7 @@ int pthread_attr_setstacksize(pthread_attr_t *attr, size_t stack_size)
{
RT_ASSERT
(
attr
!=
RT_NULL
);
attr
->
stack
_
size
=
stack_size
;
attr
->
stacksize
=
stack_size
;
return
0
;
}
...
...
@@ -127,7 +130,7 @@ int pthread_attr_getstacksize(pthread_attr_t const *attr, size_t *stack_size)
{
RT_ASSERT
(
attr
!=
RT_NULL
);
*
stack_size
=
attr
->
stack
_
size
;
*
stack_size
=
attr
->
stacksize
;
return
0
;
}
...
...
@@ -155,8 +158,8 @@ int pthread_attr_setstack(pthread_attr_t *attr,
{
RT_ASSERT
(
attr
!=
RT_NULL
);
attr
->
stack
_base
=
stack_base
;
attr
->
stack
_
size
=
RT_ALIGN_DOWN
(
stack_size
,
RT_ALIGN_SIZE
);
attr
->
stack
addr
=
stack_base
;
attr
->
stacksize
=
RT_ALIGN_DOWN
(
stack_size
,
RT_ALIGN_SIZE
);
return
0
;
}
...
...
@@ -168,8 +171,8 @@ int pthread_attr_getstack(pthread_attr_t const *attr,
{
RT_ASSERT
(
attr
!=
RT_NULL
);
*
stack_base
=
attr
->
stack
_base
;
*
stack_size
=
attr
->
stack
_
size
;
*
stack_base
=
attr
->
stack
addr
;
*
stack_size
=
attr
->
stacksize
;
return
0
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录