Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
X
xv6-public
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
问题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
银宸时代
OS Lab Group
奖励实验
xv6-public
提交
d99a5ad0
提交
d99a5ad0
3月 27, 2012
创建
作者:
Silas Boyd-Wickizer
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Make all the filetable member functions lock free.
..allocfd might still cause bottlenecks as threads race to allocate FD slots..
上级
85235464
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
11 行增加
和
23 行删除
+11
-23
filetable.hh
include/filetable.hh
+11
-23
没有找到文件。
include/filetable.hh
浏览文件 @
d99a5ad0
...
...
@@ -5,27 +5,24 @@ public:
filetable
()
:
ref_
(
1
)
{
for
(
int
fd
=
0
;
fd
<
NOFILE
;
fd
++
)
ofile_
[
fd
]
=
nullptr
;
initlock
(
&
lock_
,
"filetable"
,
0
);
}
filetable
(
const
filetable
&
f
)
:
ref_
(
1
)
{
for
(
int
fd
=
0
;
fd
<
NOFILE
;
fd
++
)
{
if
(
f
.
ofile_
[
fd
])
ofile_
[
fd
]
=
f
.
ofile_
[
fd
]
->
dup
(
);
ofile_
[
fd
]
.
store
(
f
.
ofile_
[
fd
].
load
()
->
dup
()
);
else
ofile_
[
fd
]
=
nullptr
;
}
initlock
(
&
lock_
,
"filetable"
,
0
);
}
~
filetable
()
{
for
(
int
fd
=
0
;
fd
<
NOFILE
;
fd
++
){
if
(
ofile_
[
fd
]){
ofile_
[
fd
]
->
dec
();
ofile_
[
fd
]
=
0
;
ofile_
[
fd
]
.
load
()
->
dec
();
ofile_
[
fd
]
=
nullptr
;
}
}
destroylock
(
&
lock_
);
}
bool
getfile
(
int
fd
,
sref
<
file
>
*
sf
)
{
...
...
@@ -40,15 +37,9 @@ public:
}
int
allocfd
(
struct
file
*
f
)
{
acquire
(
&
lock_
);
for
(
int
fd
=
0
;
fd
<
NOFILE
;
fd
++
)
{
if
(
ofile_
[
fd
]
==
nullptr
){
ofile_
[
fd
]
=
f
;
release
(
&
lock_
);
for
(
int
fd
=
0
;
fd
<
NOFILE
;
fd
++
)
if
(
ofile_
[
fd
]
==
nullptr
&&
cmpxch
(
&
ofile_
[
fd
],
(
file
*
)
nullptr
,
f
))
return
fd
;
}
}
release
(
&
lock_
);
cprintf
(
"filetable::allocfd: failed
\n
"
);
return
-
1
;
}
...
...
@@ -56,15 +47,13 @@ public:
void
close
(
int
fd
)
{
// XXX(sbw) if f->ref_ > 1 the kernel will not actually close
// the file when this function returns (i.e. sys_close can return
// while the file/pipe/socket is still open). Maybe we should clear
// ofile_[fd], wait until f.ref_ == 1, f->dec(), and then return.
// while the file/pipe/socket is still open).
acquire
(
&
lock_
);
struct
file
*
f
=
ofile_
[
fd
];
ofile_
[
fd
]
=
nullptr
;
release
(
&
lock_
);
if
(
f
)
file
*
f
=
ofile_
[
fd
].
exchange
(
nullptr
);
if
(
f
!=
nullptr
)
f
->
dec
();
else
cprintf
(
"filetable::close: bad fd %u
\n
"
,
fd
);
}
void
decref
()
{
...
...
@@ -79,7 +68,6 @@ public:
NEW_DELETE_OPS
(
filetable
)
private
:
st
ruct
file
*
ofile_
[
NOFILE
];
st
d
::
atomic
<
file
*>
ofile_
[
NOFILE
];
std
::
atomic
<
u64
>
ref_
;
struct
spinlock
lock_
;
};
编写
预览
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论