Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Third Party Musl
提交
00548408
T
Third Party Musl
项目概览
OpenHarmony
/
Third Party Musl
接近 2 年 前同步成功
通知
37
Star
125
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
Third Party Musl
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
00548408
编写于
10月 13, 2014
作者:
R
Rich Felker
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
eliminate global waiters count in pthread_once
上级
df37d396
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
13 addition
and
9 deletion
+13
-9
src/thread/pthread_once.c
src/thread/pthread_once.c
+13
-9
未找到文件。
src/thread/pthread_once.c
浏览文件 @
00548408
...
...
@@ -2,14 +2,14 @@
static
void
undo
(
void
*
control
)
{
a_store
(
control
,
0
);
__wake
(
control
,
1
,
1
);
/* Wake all waiters, since the waiter status is lost when
* resetting control to the initial state. */
if
(
a_swap
(
control
,
0
)
==
3
)
__wake
(
control
,
-
1
,
1
);
}
int
__pthread_once
(
pthread_once_t
*
control
,
void
(
*
init
)(
void
))
{
static
int
waiters
;
/* Return immediately if init finished before, but ensure that
* effects of the init routine are visible to the caller. */
if
(
*
control
==
2
)
{
...
...
@@ -17,10 +17,11 @@ int __pthread_once(pthread_once_t *control, void (*init)(void))
return
0
;
}
/* Try to enter initializing state.
Three
possibilities:
/* Try to enter initializing state.
Four
possibilities:
* 0 - we're the first or the other cancelled; run init
* 1 - another thread is running init; wait
* 2 - another thread finished running init; just return */
* 2 - another thread finished running init; just return
* 3 - another thread is running init, waiters present; wait */
for
(;;)
switch
(
a_cas
(
control
,
0
,
1
))
{
case
0
:
...
...
@@ -28,11 +29,14 @@ int __pthread_once(pthread_once_t *control, void (*init)(void))
init
();
pthread_cleanup_pop
(
0
);
a_store
(
control
,
2
);
if
(
waiters
)
__wake
(
control
,
-
1
,
1
);
if
(
a_swap
(
control
,
2
)
==
3
)
__wake
(
control
,
-
1
,
1
);
return
0
;
case
1
:
__wait
(
control
,
&
waiters
,
1
,
1
);
/* If this fails, so will __wait. */
a_cas
(
control
,
1
,
3
);
case
3
:
__wait
(
control
,
0
,
3
,
1
);
continue
;
case
2
:
return
0
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录