comparison src/proc.c @ 24:36bd61f5c847

rewrite sys_read cbc
author mir3636
date Thu, 17 Jan 2019 19:11:19 +0900
parents 397e74cbf14e
children 68de775c3a29
comparison
equal deleted inserted replaced
23:ee58360d0e99 24:36bd61f5c847
409 } 409 }
410 410
411 // Return to "caller", actually trapret (see allocproc). 411 // Return to "caller", actually trapret (see allocproc).
412 } 412 }
413 413
414 __code cbc_sleep1()
415 {
416 struct spinlock *lk = proc->lk;
417 // Tidy up.
418 proc->chan = 0;
419
420 // Reacquire original lock.
421 if(lk != &ptable.lock){ //DOC: sleeplock2
422 release(&ptable.lock);
423 acquire(lk);
424 }
425 goto proc->cbc_next();
426 }
427
428 __code cbc_sleep(void *chan, struct spinlock *lk, __code(*next1)())
429 {
430 //show_callstk("sleep");
431
432 if(proc == 0) {
433 panic("sleep");
434 }
435
436 if(lk == 0) {
437 panic("sleep without lk");
438 }
439
440 if(lk != &ptable.lock){ //DOC: sleeplock0
441 acquire(&ptable.lock); //DOC: sleeplock1
442 release(lk);
443 }
444 proc->chan = chan;
445 proc->state = SLEEPING;
446 proc->cbc_next = next1;
447
448 goto cbc_sched(cbc_sleep1);
449 }
450
414 // Atomically release lock and sleep on chan. 451 // Atomically release lock and sleep on chan.
415 // Reacquires lock when awakened. 452 // Reacquires lock when awakened.
416 void sleep(void *chan, struct spinlock *lk) 453 void sleep(void *chan, struct spinlock *lk)
417 { 454 {
418 //show_callstk("sleep"); 455 //show_callstk("sleep");