Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Kernel Liteos M
提交
b9c99362
K
Kernel Liteos M
项目概览
OpenHarmony
/
Kernel Liteos M
大约 1 年 前同步成功
通知
20
Star
28
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
K
Kernel Liteos M
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
b9c99362
编写于
1月 12, 2022
作者:
O
openharmony_ci
提交者:
Gitee
1月 12, 2022
浏览文件
操作
浏览文件
下载
差异文件
!509 libatomic底层实现补充
Merge pull request !509 from wangchen/atomic
上级
852114d9
2f7f6f0c
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
102 addition
and
0 deletion
+102
-0
utils/los_compiler.h
utils/los_compiler.h
+102
-0
未找到文件。
utils/los_compiler.h
浏览文件 @
b9c99362
...
@@ -418,6 +418,108 @@ static inline UINT32 LOS_Align(UINT32 addr, UINT32 boundary)
...
@@ -418,6 +418,108 @@ static inline UINT32 LOS_Align(UINT32 addr, UINT32 boundary)
#define UNUSED(X) (void)X
#define UNUSED(X) (void)X
#endif
#endif
#if defined(__GNUC__)
static
inline
void
maybe_release_fence
(
int
model
)
{
switch
(
model
)
{
case
__ATOMIC_RELEASE
:
__atomic_thread_fence
(
__ATOMIC_RELEASE
);
break
;
case
__ATOMIC_ACQ_REL
:
__atomic_thread_fence
(
__ATOMIC_ACQ_REL
);
break
;
case
__ATOMIC_SEQ_CST
:
__atomic_thread_fence
(
__ATOMIC_SEQ_CST
);
break
;
default:
break
;
}
}
static
inline
void
maybe_acquire_fence
(
int
model
)
{
switch
(
model
)
{
case
__ATOMIC_ACQUIRE
:
__atomic_thread_fence
(
__ATOMIC_ACQUIRE
);
break
;
case
__ATOMIC_ACQ_REL
:
__atomic_thread_fence
(
__ATOMIC_ACQ_REL
);
break
;
case
__ATOMIC_SEQ_CST
:
__atomic_thread_fence
(
__ATOMIC_SEQ_CST
);
break
;
default:
break
;
}
}
#define __LIBATOMIC_N_LOCKS (1 << 4)
/* 4, 1<<4 locks num */
static
inline
BOOL
*
__libatomic_flag_for_address
(
void
*
addr
)
{
static
BOOL
flag_table
[
__LIBATOMIC_N_LOCKS
]
=
{
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
};
UINTPTR
p
=
(
UINTPTR
)(
UINTPTR
*
)
addr
;
p
+=
(
p
>>
2
)
+
(
p
<<
4
);
/* 2, 4, hash data */
p
+=
(
p
>>
7
)
+
(
p
<<
5
);
/* 7, 5, hash data */
p
+=
(
p
>>
17
)
+
(
p
<<
13
);
/* 17, 13, hash data */
if
(
sizeof
(
void
*
)
>
4
)
{
/* 4, sizeof int in 32bit system */
p
+=
(
p
>>
31
);
/* 31, for hash high bits data */
}
p
&=
(
__LIBATOMIC_N_LOCKS
-
1
);
return
flag_table
+
p
;
}
static
inline
void
get_lock
(
void
*
addr
,
int
model
)
{
BOOL
*
lock_ptr
=
__libatomic_flag_for_address
(
addr
);
maybe_release_fence
(
model
);
while
(
__atomic_test_and_set
(
lock_ptr
,
__ATOMIC_ACQUIRE
)
==
1
)
{
;
}
}
static
inline
void
free_lock
(
void
*
addr
,
int
model
)
{
BOOL
*
lock_ptr
=
__libatomic_flag_for_address
(
addr
);
__atomic_clear
(
lock_ptr
,
__ATOMIC_RELEASE
);
maybe_acquire_fence
(
model
);
}
static
inline
UINT64
__atomic_load_8
(
const
volatile
void
*
mem
,
int
model
)
{
UINT64
ret
;
void
*
memP
=
(
void
*
)
mem
;
get_lock
(
memP
,
model
);
ret
=
*
(
UINT64
*
)
mem
;
free_lock
(
memP
,
model
);
return
ret
;
}
static
inline
void
__atomic_store_8
(
volatile
void
*
mem
,
UINT64
val
,
int
model
)
{
void
*
memP
=
(
void
*
)
mem
;
get_lock
(
memP
,
model
);
*
(
UINT64
*
)
mem
=
val
;
free_lock
(
memP
,
model
);
}
static
inline
UINT64
__atomic_exchange_8
(
volatile
void
*
mem
,
UINT64
val
,
int
model
)
{
UINT64
ret
;
void
*
memP
=
(
void
*
)
mem
;
get_lock
(
memP
,
model
);
ret
=
*
(
UINT64
*
)
mem
;
*
(
UINT64
*
)
mem
=
val
;
free_lock
(
memP
,
model
);
return
ret
;
}
#endif
#ifdef __cplusplus
#ifdef __cplusplus
#if __cplusplus
#if __cplusplus
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录