mirror of
https://github.com/rcore-os/rCore.git
synced 2024-11-22 08:06:17 +04:00
finish semctl.setval. pass compilation.
This commit is contained in:
parent
c241ec1f5b
commit
d4d57a5095
@ -65,13 +65,24 @@ impl Semaphore {
|
||||
SemaphoreGuard { sem: self }
|
||||
}
|
||||
|
||||
pub fn check(&self, k: isize) -> Result<bool, bool> {
|
||||
pub fn check(&self, k: isize) -> Result<bool, ()> {
|
||||
let mut count = self.lock.lock();
|
||||
Ok((*count) >= k)
|
||||
}
|
||||
|
||||
pub fn get(&self) -> Result<isize, ()> {
|
||||
let mut count = self.lock.lock();
|
||||
Ok((*count))
|
||||
}
|
||||
|
||||
pub fn set(&self, k: isize) -> Result<(), ()> {
|
||||
let mut count = self.lock.lock();
|
||||
*count = k;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Modify by k atomically. when wait is false avoid waiting.
|
||||
pub fn modify(&self, k: isize, wait: bool) -> Result<usize, usize> {
|
||||
pub fn modify(&self, k: isize, wait: bool) -> Result<usize, ()> {
|
||||
match(k) {
|
||||
k if k > 0 => {
|
||||
*(self.lock.lock()) += k;
|
||||
@ -82,7 +93,7 @@ impl Semaphore {
|
||||
let mut temp_k = k;
|
||||
while *count < temp_k {
|
||||
if wait == false {
|
||||
return Err(1)
|
||||
return Err(());
|
||||
}
|
||||
temp_k -= *count;
|
||||
*count = 0;
|
||||
@ -94,7 +105,7 @@ impl Semaphore {
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
return Err(1); //unknown error?
|
||||
return Err(()); //unknown error?
|
||||
}
|
||||
}
|
||||
Ok(0)
|
||||
|
@ -52,7 +52,7 @@ impl Syscall<'_> {
|
||||
let mut semarray: &SemArray = &*semarray_arc.lock();
|
||||
match((*semarray).sems[sembuf.sem_num as usize].modify(sembuf.sem_op as isize, true)) {
|
||||
Ok(0) => {},
|
||||
Err(1) => {
|
||||
Err(()) => {
|
||||
return Err(SysError::EAGAIN);
|
||||
},
|
||||
_ => {
|
||||
@ -66,8 +66,24 @@ impl Syscall<'_> {
|
||||
Ok(0)
|
||||
}
|
||||
|
||||
pub fn sys_semctl(&self, sem_id: usize, sem_num: usize, cmd: usize, arg: usize) -> SysResult {
|
||||
unimplemented!("Semaphore: Semctl");
|
||||
pub fn sys_semctl(&self, sem_id: usize, sem_num: usize, cmd: usize, arg: isize) -> SysResult {
|
||||
let mut proc = self.process();
|
||||
let mut semarray_table = proc.semaphores.write();
|
||||
let mut semarray_arc: Arc<Mutex<SemArray>> = (*semarray_table.get(&sem_id).unwrap()).clone();
|
||||
let mut semarray: &SemArray = &*semarray_arc.lock();
|
||||
if (cmd == SEMCTLCMD::SETVAL.bits()) {
|
||||
match (*semarray).sems[sem_num].set(arg) {
|
||||
Ok(()) => {
|
||||
return Ok(0);
|
||||
}
|
||||
_ => {
|
||||
return Err(SysError::EUNDEF);
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
unimplemented!("Semaphore: Semctl.(Not setval)");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -77,4 +93,13 @@ bitflags! {
|
||||
const IPC_NOWAIT = 0x800;
|
||||
const SEM_UNDO = 0x1000;
|
||||
}
|
||||
}
|
||||
|
||||
bitflags! {
|
||||
pub struct SEMCTLCMD: usize {
|
||||
//const GETVAL = 12;
|
||||
//const GETALL = 13;
|
||||
const SETVAL = 16;
|
||||
//const SETALL = 17;
|
||||
}
|
||||
}
|
@ -264,7 +264,7 @@ impl Syscall<'_> {
|
||||
// sem
|
||||
SYS_SEMGET => self.sys_semget(args[0], args[1], args[2]),
|
||||
SYS_SEMOP => self.sys_semop(args[0], args[1] as *const SemBuf, args[2]),
|
||||
SYS_SEMCTL => self.sys_semctl(args[0], args[1], args[2], args[3]/* as SemctlUnion*/),
|
||||
SYS_SEMCTL => self.sys_semctl(args[0], args[1], args[2], args[3] as isize/* as SemctlUnion*/),
|
||||
|
||||
// system
|
||||
SYS_GETPID => self.sys_getpid(),
|
||||
|
Loading…
Reference in New Issue
Block a user