浏览代码

cargo fmt

xiaolin2004 4 月之前
父节点
当前提交
76c3935bf7
共有 2 个文件被更改,包括 13 次插入15 次删除
  1. 5 7
      kernel/src/ipc/pipe.rs
  2. 8 8
      user/apps/test_fifo_write/main.c

+ 5 - 7
kernel/src/ipc/pipe.rs

@@ -288,18 +288,16 @@ impl IndexNode for LockedPipeInode {
         let accmode = mode.accmode();
         let mut guard = self.inner.lock();
         // 不能以读写方式打开管道
-        if accmode==FileMode::O_RDWR.bits() {
+        if accmode == FileMode::O_RDWR.bits() {
             return Err(SystemError::EACCES);
-        }
-        else if accmode==FileMode::O_RDONLY.bits() {
+        } else if accmode == FileMode::O_RDONLY.bits() {
             guard.reader += 1;
             guard.had_reader = true;
             println!(
                 "FIFO:     pipe try open in read mode with reader pid:{:?}",
                 ProcessManager::current_pid()
             );
-        }
-        else if accmode==FileMode::O_WRONLY.bits() {
+        } else if accmode == FileMode::O_WRONLY.bits() {
             println!(
                 "FIFO:     pipe try open in write mode with {} reader, writer pid:{:?}",
                 guard.reader,
@@ -338,7 +336,7 @@ impl IndexNode for LockedPipeInode {
         let mut guard = self.inner.lock();
 
         // 写端关闭
-        if accmode==FileMode::O_WRONLY.bits() {
+        if accmode == FileMode::O_WRONLY.bits() {
             assert!(guard.writer > 0);
             guard.writer -= 1;
             // 如果已经没有写端了,则唤醒读端
@@ -349,7 +347,7 @@ impl IndexNode for LockedPipeInode {
         }
 
         // 读端关闭
-        if accmode==FileMode::O_RDONLY.bits() {
+        if accmode == FileMode::O_RDONLY.bits() {
             assert!(guard.reader > 0);
             guard.reader -= 1;
             // 如果已经没有写端了,则唤醒读端

+ 8 - 8
user/apps/test_fifo_write/main.c

@@ -118,16 +118,16 @@ int main() {
     }
 
     // 测试阻塞模式下的三种情况
-    printf("========== Testing Blocking Mode ==========\n");
-    test_case1(0); // 阻塞模式下没有读端
-    test_case2(0); // 阻塞模式下读端断开
-    test_case3(0); // 阻塞模式下读端存在
+    // printf("========== Testing Blocking Mode ==========\n");
+    // test_case1(0); // 阻塞模式下没有读端
+    // test_case2(0); // 阻塞模式下读端断开
+    // test_case3(0); // 阻塞模式下读端存在
 
     // 测试非阻塞模式下的三种情况
-    // printf("\n========== Testing Nonblocking Mode ==========\n");
-    // test_case1(1); // 非阻塞模式下没有读端
-    // test_case2(1); // 非阻塞模式下读端断开
-    // test_case3(1); // 非阻塞模式下读端存在
+    printf("\n========== Testing Nonblocking Mode ==========\n");
+    test_case1(1); // 非阻塞模式下没有读端
+    test_case2(1); // 非阻塞模式下读端断开
+    test_case3(1); // 非阻塞模式下读端存在
 
     // 删除 FIFO
     unlink(FIFO_PATH);