fix broken pipe status. rustc works now!

master
WangRunji 6 years ago
parent 6bb11a5433
commit 6e5b3e2515

@ -45,13 +45,25 @@ impl Pipe {
)
}
pub fn can_read(&self) -> bool {
fn can_read(&self) -> bool {
if let PipeEnd::Read = self.direction {
self.data.lock().buf.len() > 0
self.data.lock().buf.len() > 0 || self.is_broken()
} else {
false
}
}
fn can_write(&self) -> bool {
if let PipeEnd::Write = self.direction {
!self.is_broken()
} else {
false
}
}
fn is_broken(&self) -> bool {
Arc::strong_count(&self.data) < 2
}
}
// TODO: better way to provide default impl?
@ -105,39 +117,11 @@ impl INode for Pipe {
}
fn poll(&self) -> Result<PollStatus> {
let data = self.data.lock();
match self.direction {
PipeEnd::Read => {
if data.buf.len() > 0 {
Ok(PollStatus {
read: true,
write: false,
error: false,
})
} else {
Ok(PollStatus {
read: false,
write: false,
error: false,
})
}
}
PipeEnd::Write => {
if data.buf.len() > 0 {
Ok(PollStatus {
read: false,
write: true,
error: false,
})
} else {
Ok(PollStatus {
read: false,
write: false,
error: false,
})
}
}
}
Ok(PollStatus {
read: self.can_read(),
write: self.can_write(),
error: false,
})
}
impl_inode!();
}

@ -141,6 +141,9 @@ impl Syscall<'_> {
return Ok(0);
}
// NOTE: To run rustc, uncomment yield_now and comment Condvar.
// Waking up from pipe is unimplemented now.
// thread::yield_now();
Condvar::wait_any(&[&STDIN.pushed, &(*SOCKET_ACTIVITY)]);
}
}
@ -1416,6 +1419,7 @@ impl IoVecs {
}
#[repr(C)]
#[derive(Debug)]
pub struct PollFd {
fd: u32,
events: PollEvents,

@ -69,10 +69,9 @@ impl Syscall<'_> {
val,
timeout
);
// if op & OP_PRIVATE == 0 {
// unimplemented!("futex only support process-private");
// return Err(SysError::ENOSYS);
// }
if op & OP_PRIVATE == 0 {
warn!("process-shared futex is unimplemented");
}
if uaddr % size_of::<u32>() != 0 {
return Err(SysError::EINVAL);
}
@ -80,7 +79,7 @@ impl Syscall<'_> {
const OP_WAIT: u32 = 0;
const OP_WAKE: u32 = 1;
const OP_PRIVATE: u32 = 128;
const OP_PRIVATE: u32 = 0x80;
let mut proc = self.process();
let queue = proc.get_futex(uaddr);

Loading…
Cancel
Save