Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
X
xv6-public
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
问题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
银宸时代
OS Lab Group
奖励实验
xv6-public
提交
07cad277
提交
07cad277
3月 24, 2012
创建
作者:
Nickolai Zeldovich
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
per-core lists of all elements in a namespace.
enumerate() starts with the local core's elements first.
上级
bba8fe0a
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
36 行增加
和
7 行删除
+36
-7
ns.hh
include/ns.hh
+36
-7
没有找到文件。
include/ns.hh
浏览文件 @
07cad277
#pragma once
#include "gc.hh"
#include "percpu.hh"
// name spaces
// XXX maybe use open hash table, no chain, better cache locality
...
...
@@ -15,11 +16,19 @@ template<class K, class V>
class
xelem
:
public
rcu_freed
{
public
:
V
val
;
std
::
atomic
<
int
>
next_lock
;
std
::
atomic
<
xelem
<
K
,
V
>*>
volatile
next
;
K
key
;
xelem
(
const
K
&
k
,
const
V
&
v
)
:
rcu_freed
(
"xelem"
),
val
(
v
),
next_lock
(
0
),
next
(
0
),
key
(
k
)
{}
std
::
atomic
<
int
>
next_lock
;
std
::
atomic
<
xelem
<
K
,
V
>*>
next
;
int
percore_c
;
std
::
atomic
<
xelem
<
K
,
V
>*>
percore_next
;
std
::
atomic
<
xelem
<
K
,
V
>*>*
percore_pprev
;
xelem
(
const
K
&
k
,
const
V
&
v
)
:
rcu_freed
(
"xelem"
),
val
(
v
),
key
(
k
),
next_lock
(
0
),
next
(
0
),
percore_next
(
0
),
percore_pprev
(
0
)
{}
virtual
void
do_gc
()
{
delete
this
;
}
...
...
@@ -38,6 +47,8 @@ class xns : public rcu_freed {
bool
allowdup
;
std
::
atomic
<
u64
>
nextkey
;
xbucket
<
K
,
V
>
table
[
NHASH
];
std
::
atomic
<
xelem
<
K
,
V
>*>
percore
[
NCPU
];
spinlock
percore_lock
[
NCPU
];
public
:
xns
(
bool
dup
)
:
rcu_freed
(
"xns"
)
{
...
...
@@ -85,8 +96,18 @@ class xns : public rcu_freed {
}
e
->
next
=
root
.
load
();
if
(
cmpxch
(
&
table
[
i
].
chain
,
e
->
next
.
load
(),
e
))
if
(
cmpxch
(
&
table
[
i
].
chain
,
e
->
next
.
load
(),
e
))
{
int
c
=
mycpuid
();
acquire
(
&
percore_lock
[
c
]);
e
->
percore_c
=
c
;
e
->
percore_next
=
percore
[
c
].
load
();
if
(
percore
[
c
])
percore
[
c
].
load
()
->
percore_pprev
=
&
e
->
percore_next
;
e
->
percore_pprev
=
&
percore
[
c
];
percore
[
c
]
=
e
;
release
(
&
percore_lock
[
c
]);
return
0
;
}
}
}
...
...
@@ -133,6 +154,13 @@ class xns : public rcu_freed {
break
;
}
int
c
=
e
->
percore_c
;
acquire
(
&
percore_lock
[
c
]);
*
e
->
percore_pprev
=
e
->
percore_next
.
load
();
if
(
e
->
percore_next
)
e
->
percore_next
.
load
()
->
percore_pprev
=
e
->
percore_pprev
;
release
(
&
percore_lock
[
c
]);
*
pelock
=
0
;
gc_delayed
(
e
);
return
true
;
...
...
@@ -147,12 +175,13 @@ class xns : public rcu_freed {
template
<
class
CB
>
void
enumerate
(
CB
cb
)
{
scoped_gc_epoch
gc
;
for
(
int
i
=
0
;
i
<
NHASH
;
i
++
)
{
auto
e
=
table
[
i
].
chain
.
load
();
int
cpuoffset
=
mycpuid
();
for
(
int
i
=
0
;
i
<
NCPU
;
i
++
)
{
auto
e
=
percore
[(
i
+
cpuoffset
)
%
NCPU
].
load
();
while
(
e
)
{
if
(
cb
(
e
->
key
,
e
->
val
))
return
;
e
=
e
->
next
;
e
=
e
->
percore_
next
;
}
}
}
...
...
编写
预览
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论