wakeup
This commit is contained in:
parent
8dc10d24f0
commit
954db4c998
@ -87,7 +87,6 @@ struct proc *myproc();
|
|||||||
void procinit(void);
|
void procinit(void);
|
||||||
void sleep_lock(void *, struct spinlock *);
|
void sleep_lock(void *, struct spinlock *);
|
||||||
void userinit(void);
|
void userinit(void);
|
||||||
void wakeup(void *);
|
|
||||||
int either_copyout(int user_dst, uint64 dst, void *src, uint64 len);
|
int either_copyout(int user_dst, uint64 dst, void *src, uint64 len);
|
||||||
int either_copyin(void *dst, int user_src, uint64 src, uint64 len);
|
int either_copyin(void *dst, int user_src, uint64 src, uint64 len);
|
||||||
void procdump(void);
|
void procdump(void);
|
||||||
|
@ -129,23 +129,6 @@ forkret(void)
|
|||||||
// Reacquires lock when awakened.
|
// Reacquires lock when awakened.
|
||||||
void sleep_lock(void *chan, struct spinlock *lk);
|
void sleep_lock(void *chan, struct spinlock *lk);
|
||||||
|
|
||||||
// Wake up all processes sleeping on chan.
|
|
||||||
// Must be called without any p->lock.
|
|
||||||
void wakeup(void *chan)
|
|
||||||
{
|
|
||||||
struct proc *p;
|
|
||||||
|
|
||||||
for(p = proc; p < &proc[NPROC]; p++) {
|
|
||||||
if(p != myproc()){
|
|
||||||
acquire(&p->lock);
|
|
||||||
if(p->state == SLEEPING && p->chan == chan) {
|
|
||||||
p->state = RUNNABLE;
|
|
||||||
}
|
|
||||||
release(&p->lock);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Copy to either a user address, or kernel address,
|
// Copy to either a user address, or kernel address,
|
||||||
// depending on usr_dst.
|
// depending on usr_dst.
|
||||||
// Returns 0 on success, -1 on error.
|
// Returns 0 on success, -1 on error.
|
||||||
|
@ -146,6 +146,9 @@ impl Process {
|
|||||||
unsafe { Some(&mut *p) }
|
unsafe { Some(&mut *p) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
pub fn is_current(&self) -> bool {
|
||||||
|
addr_of!(*self).cast_mut() == Cpu::current().proc
|
||||||
|
}
|
||||||
|
|
||||||
pub fn alloc_pid() -> i32 {
|
pub fn alloc_pid() -> i32 {
|
||||||
NEXT_PID.fetch_add(1, Ordering::SeqCst)
|
NEXT_PID.fetch_add(1, Ordering::SeqCst)
|
||||||
|
@ -13,7 +13,7 @@ use core::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
pub fn wakeup(chan: *const c_void);
|
// pub fn wakeup(chan: *const c_void);
|
||||||
// pub fn scheduler() -> !;
|
// pub fn scheduler() -> !;
|
||||||
pub fn swtch(a: *mut Context, b: *mut Context);
|
pub fn swtch(a: *mut Context, b: *mut Context);
|
||||||
}
|
}
|
||||||
@ -109,3 +109,17 @@ pub unsafe fn sleep(chan: *mut c_void) {
|
|||||||
// Tidy up.
|
// Tidy up.
|
||||||
p.chan = null_mut();
|
p.chan = null_mut();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Wake up all processes sleeping on chan.
|
||||||
|
/// Must be called without any p.lock.
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn wakeup(chan: *mut c_void) {
|
||||||
|
for p in &mut proc {
|
||||||
|
if !p.is_current() {
|
||||||
|
let _guard = p.lock.lock();
|
||||||
|
if p.state == ProcessState::Sleeping && p.chan == chan {
|
||||||
|
p.state = ProcessState::Runnable;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user