diff src/proc.c @ 24:36bd61f5c847

rewrite sys_read cbc
author mir3636
date Thu, 17 Jan 2019 19:11:19 +0900
parents 397e74cbf14e
children 68de775c3a29
line wrap: on
line diff
--- a/src/proc.c	Mon Dec 17 16:55:22 2018 +0900
+++ b/src/proc.c	Thu Jan 17 19:11:19 2019 +0900
@@ -411,6 +411,43 @@
     // Return to "caller", actually trapret (see allocproc).
 }
 
+__code cbc_sleep1()
+{
+    struct spinlock *lk = proc->lk;
+    // Tidy up.
+    proc->chan = 0;
+
+    // Reacquire original lock.
+    if(lk != &ptable.lock){  //DOC: sleeplock2
+        release(&ptable.lock);
+        acquire(lk);
+    }
+    goto proc->cbc_next();
+}
+
+__code cbc_sleep(void *chan, struct spinlock *lk, __code(*next1)())
+{
+    //show_callstk("sleep");
+
+    if(proc == 0) {
+        panic("sleep");
+    }
+
+    if(lk == 0) {
+        panic("sleep without lk");
+    }
+
+    if(lk != &ptable.lock){  //DOC: sleeplock0
+        acquire(&ptable.lock);  //DOC: sleeplock1
+        release(lk);
+    }
+    proc->chan = chan;
+    proc->state = SLEEPING;
+    proc->cbc_next = next1;
+
+    goto cbc_sched(cbc_sleep1);
+}
+
 // Atomically release lock and sleep on chan.
 // Reacquires lock when awakened.
 void sleep(void *chan, struct spinlock *lk)