Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
rcore-os
RCore Tutorial V3
提交
07c6cb36
R
RCore Tutorial V3
项目概览
rcore-os
/
RCore Tutorial V3
上一次同步 1 年多
通知
15
Star
793
Fork
260
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
4
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
RCore Tutorial V3
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
4
Issue
4
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
07c6cb36
编写于
12月 23, 2022
作者:
Y
Yifan Wu
1
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix pipe impl
上级
b6d685db
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
16 addition
and
9 deletion
+16
-9
os/src/fs/pipe.rs
os/src/fs/pipe.rs
+16
-9
未找到文件。
os/src/fs/pipe.rs
浏览文件 @
07c6cb36
...
...
@@ -114,36 +114,40 @@ impl File for Pipe {
}
fn
read
(
&
self
,
buf
:
UserBuffer
)
->
usize
{
assert
!
(
self
.readable
());
let
want_to_read
=
buf
.len
();
let
mut
buf_iter
=
buf
.into_iter
();
let
mut
read_size
=
0u
size
;
let
mut
already_read
=
0u
size
;
loop
{
let
mut
ring_buffer
=
self
.buffer
.exclusive_access
();
let
loop_read
=
ring_buffer
.available_read
();
if
loop_read
==
0
{
if
ring_buffer
.all_write_ends_closed
()
{
return
read_size
;
return
already_read
;
}
drop
(
ring_buffer
);
suspend_current_and_run_next
();
continue
;
}
// read at most loop_read bytes
for
_
in
0
..
loop_read
{
if
let
Some
(
byte_ref
)
=
buf_iter
.next
()
{
unsafe
{
*
byte_ref
=
ring_buffer
.read_byte
();
}
read_size
+=
1
;
already_read
+=
1
;
if
already_read
==
want_to_read
{
return
want_to_read
;
}
}
else
{
return
read_size
;
return
already_read
;
}
}
}
}
fn
write
(
&
self
,
buf
:
UserBuffer
)
->
usize
{
assert
!
(
self
.writable
());
let
want_to_write
=
buf
.len
();
let
mut
buf_iter
=
buf
.into_iter
();
let
mut
write_siz
e
=
0u
size
;
let
mut
already_writ
e
=
0u
size
;
loop
{
let
mut
ring_buffer
=
self
.buffer
.exclusive_access
();
let
loop_write
=
ring_buffer
.available_write
();
...
...
@@ -156,11 +160,14 @@ impl File for Pipe {
for
_
in
0
..
loop_write
{
if
let
Some
(
byte_ref
)
=
buf_iter
.next
()
{
ring_buffer
.write_byte
(
unsafe
{
*
byte_ref
});
write_size
+=
1
;
already_write
+=
1
;
if
already_write
==
want_to_write
{
return
want_to_write
;
}
}
else
{
return
write_siz
e
;
return
already_writ
e
;
}
}
}
}
}
}
\ No newline at end of file
Miykael_xxm
🚴
@xiongjiamu
mentioned in commit
44559e9b
·
12月 24, 2022
mentioned in commit
44559e9b
mentioned in commit 44559e9b41fb98763e2455c1cd4c5d5f9eb0a287
开关提交列表
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录