Small Fix && cargo fmt
This commit is contained in:
parent
c9583b0f53
commit
ae3ba9c26f
83 changed files with 1085 additions and 1079 deletions
|
@ -5,12 +5,7 @@
|
|||
extern crate user_lib;
|
||||
extern crate alloc;
|
||||
|
||||
use user_lib::{
|
||||
open,
|
||||
OpenFlags,
|
||||
close,
|
||||
read,
|
||||
};
|
||||
use user_lib::{close, open, read, OpenFlags};
|
||||
|
||||
#[no_mangle]
|
||||
pub fn main(argc: usize, argv: &[&str]) -> i32 {
|
||||
|
@ -23,7 +18,9 @@ pub fn main(argc: usize, argv: &[&str]) -> i32 {
|
|||
let mut buf = [0u8; 16];
|
||||
loop {
|
||||
let size = read(fd, &mut buf) as usize;
|
||||
if size == 0 { break; }
|
||||
if size == 0 {
|
||||
break;
|
||||
}
|
||||
println!("{}", core::str::from_utf8(&buf[..size]).unwrap());
|
||||
}
|
||||
close(fd);
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
#[macro_use]
|
||||
extern crate user_lib;
|
||||
use user_lib::{fork, yield_, waitpid, exit, wait};
|
||||
use user_lib::{exit, fork, wait, waitpid, yield_};
|
||||
|
||||
const MAGIC: i32 = -0x10384;
|
||||
|
||||
|
@ -13,7 +13,9 @@ pub fn main() -> i32 {
|
|||
let pid = fork();
|
||||
if pid == 0 {
|
||||
println!("I am the child.");
|
||||
for _ in 0..7 { yield_(); }
|
||||
for _ in 0..7 {
|
||||
yield_();
|
||||
}
|
||||
exit(MAGIC);
|
||||
} else {
|
||||
println!("I am parent, fork a child pid {}", pid);
|
||||
|
@ -26,4 +28,3 @@ pub fn main() -> i32 {
|
|||
println!("exit pass.");
|
||||
0
|
||||
}
|
||||
|
||||
|
|
|
@ -41,4 +41,4 @@ pub fn main() -> i32 {
|
|||
println!("{}", color_text!(text, i));
|
||||
}
|
||||
0
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,13 +4,7 @@
|
|||
#[macro_use]
|
||||
extern crate user_lib;
|
||||
|
||||
use user_lib::{
|
||||
open,
|
||||
close,
|
||||
read,
|
||||
write,
|
||||
OpenFlags,
|
||||
};
|
||||
use user_lib::{close, open, read, write, OpenFlags};
|
||||
|
||||
#[no_mangle]
|
||||
pub fn main() -> i32 {
|
||||
|
@ -29,10 +23,7 @@ pub fn main() -> i32 {
|
|||
let read_len = read(fd, &mut buffer) as usize;
|
||||
close(fd);
|
||||
|
||||
assert_eq!(
|
||||
test_str,
|
||||
core::str::from_utf8(&buffer[..read_len]).unwrap(),
|
||||
);
|
||||
assert_eq!(test_str, core::str::from_utf8(&buffer[..read_len]).unwrap(),);
|
||||
println!("file_test passed!");
|
||||
0
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#[macro_use]
|
||||
extern crate user_lib;
|
||||
|
||||
use user_lib::{fork, wait, exit};
|
||||
use user_lib::{exit, fork, wait};
|
||||
|
||||
const MAX_CHILD: usize = 30;
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#[macro_use]
|
||||
extern crate user_lib;
|
||||
|
||||
use user_lib::{fork, wait, getpid, exit, sleep, get_time};
|
||||
use user_lib::{exit, fork, get_time, getpid, sleep, wait};
|
||||
|
||||
static NUM: usize = 30;
|
||||
|
||||
|
@ -14,7 +14,8 @@ pub fn main() -> i32 {
|
|||
let pid = fork();
|
||||
if pid == 0 {
|
||||
let current_time = get_time();
|
||||
let sleep_length = (current_time as i32 as isize) * (current_time as i32 as isize) % 1000 + 1000;
|
||||
let sleep_length =
|
||||
(current_time as i32 as isize) * (current_time as i32 as isize) % 1000 + 1000;
|
||||
println!("pid {} sleep for {} ms", getpid(), sleep_length);
|
||||
sleep(sleep_length as usize);
|
||||
println!("pid {} OK!", getpid());
|
||||
|
@ -30,4 +31,4 @@ pub fn main() -> i32 {
|
|||
assert!(wait(&mut exit_code) < 0);
|
||||
println!("forktest2 test passed!");
|
||||
0
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,4 +25,4 @@ pub fn main() -> i32 {
|
|||
println!("child process pid = {}, exit code = {}", pid, exit_code);
|
||||
0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#[macro_use]
|
||||
extern crate user_lib;
|
||||
|
||||
use user_lib::{sleep, getpid, fork, exit, yield_};
|
||||
use user_lib::{exit, fork, getpid, sleep, yield_};
|
||||
|
||||
const DEPTH: usize = 4;
|
||||
|
||||
|
|
|
@ -8,4 +8,4 @@ extern crate user_lib;
|
|||
pub fn main() -> i32 {
|
||||
println!("Hello world from user mode program!");
|
||||
0
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,13 +4,7 @@
|
|||
#[macro_use]
|
||||
extern crate user_lib;
|
||||
|
||||
use user_lib::{
|
||||
OpenFlags,
|
||||
open,
|
||||
close,
|
||||
write,
|
||||
get_time,
|
||||
};
|
||||
use user_lib::{close, get_time, open, write, OpenFlags};
|
||||
|
||||
#[no_mangle]
|
||||
pub fn main() -> i32 {
|
||||
|
@ -25,12 +19,15 @@ pub fn main() -> i32 {
|
|||
let f = f as usize;
|
||||
let start = get_time();
|
||||
let size_mb = 1usize;
|
||||
for _ in 0..1024*size_mb {
|
||||
for _ in 0..1024 * size_mb {
|
||||
write(f, &buffer);
|
||||
}
|
||||
close(f);
|
||||
let time_ms = (get_time() - start) as usize;
|
||||
let speed_kbs = size_mb * 1000000 / time_ms;
|
||||
println!("{}MiB written, time cost = {}ms, write speed = {}KiB/s", size_mb, time_ms, speed_kbs);
|
||||
println!(
|
||||
"{}MiB written, time cost = {}ms, write speed = {}KiB/s",
|
||||
size_mb, time_ms, speed_kbs
|
||||
);
|
||||
0
|
||||
}
|
||||
|
|
|
@ -3,12 +3,7 @@
|
|||
|
||||
extern crate user_lib;
|
||||
|
||||
use user_lib::{
|
||||
fork,
|
||||
wait,
|
||||
exec,
|
||||
yield_,
|
||||
};
|
||||
use user_lib::{exec, fork, wait, yield_};
|
||||
|
||||
#[no_mangle]
|
||||
fn main() -> i32 {
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
#[macro_use]
|
||||
extern crate user_lib;
|
||||
|
||||
use user_lib::{fork, wait, yield_, exit, getpid, get_time};
|
||||
use user_lib::{exit, fork, get_time, getpid, wait, yield_};
|
||||
|
||||
static NUM: usize = 30;
|
||||
const N: usize = 10;
|
||||
|
|
|
@ -7,10 +7,10 @@ extern crate user_lib;
|
|||
|
||||
extern crate alloc;
|
||||
|
||||
use user_lib::{semaphore_create, semaphore_up, semaphore_down};
|
||||
use user_lib::{thread_create, waittid};
|
||||
use user_lib::exit;
|
||||
use alloc::vec::Vec;
|
||||
use user_lib::exit;
|
||||
use user_lib::{semaphore_create, semaphore_down, semaphore_up};
|
||||
use user_lib::{thread_create, waittid};
|
||||
|
||||
const SEM_MUTEX: usize = 0;
|
||||
const SEM_EMPTY: usize = 1;
|
||||
|
@ -58,7 +58,10 @@ pub fn main() -> i32 {
|
|||
let ids: Vec<_> = (0..PRODUCER_COUNT).collect();
|
||||
let mut threads = Vec::new();
|
||||
for i in 0..PRODUCER_COUNT {
|
||||
threads.push(thread_create(producer as usize, &ids.as_slice()[i] as *const _ as usize));
|
||||
threads.push(thread_create(
|
||||
producer as usize,
|
||||
&ids.as_slice()[i] as *const _ as usize,
|
||||
));
|
||||
}
|
||||
threads.push(thread_create(consumer as usize, 0));
|
||||
// wait for all threads to complete
|
||||
|
|
|
@ -6,10 +6,10 @@
|
|||
extern crate user_lib;
|
||||
extern crate alloc;
|
||||
|
||||
use alloc::vec::Vec;
|
||||
use user_lib::{exit, get_time, sleep};
|
||||
use user_lib::{mutex_blocking_create, mutex_lock, mutex_unlock};
|
||||
use user_lib::{thread_create, waittid};
|
||||
use user_lib::{sleep, exit, get_time};
|
||||
use alloc::vec::Vec;
|
||||
|
||||
const N: usize = 5;
|
||||
const ROUND: usize = 4;
|
||||
|
@ -39,16 +39,24 @@ fn philosopher_dining_problem(id: *const usize) {
|
|||
let max = left + right - min;
|
||||
for round in 0..ROUND {
|
||||
// thinking
|
||||
unsafe { THINK[id][2 * round] = get_time_u(); }
|
||||
unsafe {
|
||||
THINK[id][2 * round] = get_time_u();
|
||||
}
|
||||
sleep(ARR[id][2 * round]);
|
||||
unsafe { THINK[id][2 * round + 1] = get_time_u(); }
|
||||
unsafe {
|
||||
THINK[id][2 * round + 1] = get_time_u();
|
||||
}
|
||||
// wait for forks
|
||||
mutex_lock(min);
|
||||
mutex_lock(max);
|
||||
// eating
|
||||
unsafe { EAT[id][2 * round] = get_time_u(); }
|
||||
unsafe {
|
||||
EAT[id][2 * round] = get_time_u();
|
||||
}
|
||||
sleep(ARR[id][2 * round + 1]);
|
||||
unsafe { EAT[id][2 * round + 1] = get_time_u(); }
|
||||
unsafe {
|
||||
EAT[id][2 * round + 1] = get_time_u();
|
||||
}
|
||||
mutex_unlock(max);
|
||||
mutex_unlock(min);
|
||||
}
|
||||
|
@ -62,7 +70,10 @@ pub fn main() -> i32 {
|
|||
let start = get_time_u();
|
||||
for i in 0..N {
|
||||
assert_eq!(mutex_blocking_create(), i as isize);
|
||||
v.push(thread_create(philosopher_dining_problem as usize, &ids.as_slice()[i] as *const _ as usize));
|
||||
v.push(thread_create(
|
||||
philosopher_dining_problem as usize,
|
||||
&ids.as_slice()[i] as *const _ as usize,
|
||||
));
|
||||
}
|
||||
for tid in v.iter() {
|
||||
waittid(*tid as usize);
|
||||
|
@ -71,8 +82,8 @@ pub fn main() -> i32 {
|
|||
println!("time cost = {}", time_cost);
|
||||
println!("'-' -> THINKING; 'x' -> EATING; ' ' -> WAITING ");
|
||||
for id in (0..N).into_iter().chain(0..=0) {
|
||||
print!("#{}:", id);
|
||||
for j in 0..time_cost/GRAPH_SCALE {
|
||||
print!("#{}:", id);
|
||||
for j in 0..time_cost / GRAPH_SCALE {
|
||||
let current_time = j * GRAPH_SCALE + start;
|
||||
if (0..ROUND).any(|round| unsafe {
|
||||
let start_thinking = THINK[id][2 * round];
|
||||
|
|
|
@ -6,8 +6,8 @@ extern crate user_lib;
|
|||
|
||||
extern crate alloc;
|
||||
|
||||
use user_lib::{fork, close, pipe, read, write, wait, get_time};
|
||||
use alloc::format;
|
||||
use user_lib::{close, fork, get_time, pipe, read, wait, write};
|
||||
|
||||
const LENGTH: usize = 3000;
|
||||
#[no_mangle]
|
||||
|
@ -44,7 +44,10 @@ pub fn main() -> i32 {
|
|||
*ch = get_time() as u8;
|
||||
}
|
||||
// send it
|
||||
assert_eq!(write(down_pipe_fd[1], &random_str) as usize, random_str.len());
|
||||
assert_eq!(
|
||||
write(down_pipe_fd[1], &random_str) as usize,
|
||||
random_str.len()
|
||||
);
|
||||
// close write end of down pipe
|
||||
close(down_pipe_fd[1]);
|
||||
// calculate sum(parent)
|
||||
|
@ -57,9 +60,8 @@ pub fn main() -> i32 {
|
|||
// check
|
||||
assert_eq!(
|
||||
sum,
|
||||
str::parse::<usize>(
|
||||
core::str::from_utf8(&child_result[..result_len]).unwrap()
|
||||
).unwrap()
|
||||
str::parse::<usize>(core::str::from_utf8(&child_result[..result_len]).unwrap())
|
||||
.unwrap()
|
||||
);
|
||||
let mut _unused: i32 = 0;
|
||||
wait(&mut _unused);
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#[macro_use]
|
||||
extern crate user_lib;
|
||||
|
||||
use user_lib::{fork, close, pipe, read, write, wait};
|
||||
use user_lib::{close, fork, pipe, read, wait, write};
|
||||
|
||||
static STR: &str = "Hello, world!";
|
||||
|
||||
|
@ -41,4 +41,4 @@ pub fn main() -> i32 {
|
|||
println!("pipetest passed!");
|
||||
0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
extern crate user_lib;
|
||||
extern crate alloc;
|
||||
|
||||
use user_lib::{exit, thread_create, waittid, get_time};
|
||||
use alloc::vec::Vec;
|
||||
use user_lib::{exit, get_time, thread_create, waittid};
|
||||
|
||||
static mut A: usize = 0;
|
||||
const PER_THREAD: usize = 1000;
|
||||
|
@ -17,7 +17,9 @@ unsafe fn f() -> ! {
|
|||
for _ in 0..PER_THREAD {
|
||||
let a = &mut A as *mut usize;
|
||||
let cur = a.read_volatile();
|
||||
for _ in 0..500 { t = t * t % 10007; }
|
||||
for _ in 0..500 {
|
||||
t = t * t % 10007;
|
||||
}
|
||||
a.write_volatile(cur + 1);
|
||||
}
|
||||
exit(t as i32)
|
||||
|
@ -26,7 +28,7 @@ unsafe fn f() -> ! {
|
|||
#[no_mangle]
|
||||
pub fn main() -> i32 {
|
||||
let start = get_time();
|
||||
let mut v = Vec::new();
|
||||
let mut v = Vec::new();
|
||||
for _ in 0..THREAD_COUNT {
|
||||
v.push(thread_create(f as usize, 0) as usize);
|
||||
}
|
||||
|
|
|
@ -5,16 +5,15 @@
|
|||
extern crate user_lib;
|
||||
extern crate alloc;
|
||||
|
||||
use alloc::vec::Vec;
|
||||
use crate::alloc::string::ToString;
|
||||
use alloc::vec::Vec;
|
||||
use user_lib::{exit, get_time, thread_create, waittid};
|
||||
|
||||
|
||||
static mut A: usize = 0;
|
||||
const PER_THREAD: usize = 1000;
|
||||
const THREAD_COUNT: usize = 16;
|
||||
|
||||
unsafe fn f(count:usize) -> ! {
|
||||
unsafe fn f(count: usize) -> ! {
|
||||
let mut t = 2usize;
|
||||
for _ in 0..PER_THREAD {
|
||||
let a = &mut A as *mut usize;
|
||||
|
|
|
@ -5,9 +5,9 @@
|
|||
extern crate user_lib;
|
||||
extern crate alloc;
|
||||
|
||||
use user_lib::{exit, thread_create, waittid, get_time, yield_};
|
||||
use alloc::vec::Vec;
|
||||
use core::sync::atomic::{AtomicBool, Ordering};
|
||||
use user_lib::{exit, get_time, thread_create, waittid, yield_};
|
||||
|
||||
static mut A: usize = 0;
|
||||
static OCCUPIED: AtomicBool = AtomicBool::new(false);
|
||||
|
@ -17,12 +17,17 @@ const THREAD_COUNT: usize = 16;
|
|||
unsafe fn f() -> ! {
|
||||
let mut t = 2usize;
|
||||
for _ in 0..PER_THREAD {
|
||||
while OCCUPIED.compare_exchange(false, true, Ordering::Relaxed, Ordering::Relaxed).is_err() {
|
||||
while OCCUPIED
|
||||
.compare_exchange(false, true, Ordering::Relaxed, Ordering::Relaxed)
|
||||
.is_err()
|
||||
{
|
||||
yield_();
|
||||
}
|
||||
let a = &mut A as *mut usize;
|
||||
let cur = a.read_volatile();
|
||||
for _ in 0..500 { t = t * t % 10007; }
|
||||
for _ in 0..500 {
|
||||
t = t * t % 10007;
|
||||
}
|
||||
a.write_volatile(cur + 1);
|
||||
OCCUPIED.store(false, Ordering::Relaxed);
|
||||
}
|
||||
|
@ -32,7 +37,7 @@ unsafe fn f() -> ! {
|
|||
#[no_mangle]
|
||||
pub fn main() -> i32 {
|
||||
let start = get_time();
|
||||
let mut v = Vec::new();
|
||||
let mut v = Vec::new();
|
||||
for _ in 0..THREAD_COUNT {
|
||||
v.push(thread_create(f as usize, 0) as usize);
|
||||
}
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
extern crate user_lib;
|
||||
extern crate alloc;
|
||||
|
||||
use user_lib::{exit, thread_create, waittid, get_time, yield_};
|
||||
use alloc::vec::Vec;
|
||||
use user_lib::{exit, get_time, thread_create, waittid, yield_};
|
||||
|
||||
static mut A: usize = 0;
|
||||
static mut OCCUPIED: bool = false;
|
||||
|
@ -16,12 +16,16 @@ const THREAD_COUNT: usize = 16;
|
|||
unsafe fn f() -> ! {
|
||||
let mut t = 2usize;
|
||||
for _ in 0..PER_THREAD {
|
||||
while OCCUPIED { yield_(); }
|
||||
while OCCUPIED {
|
||||
yield_();
|
||||
}
|
||||
OCCUPIED = true;
|
||||
// enter critical section
|
||||
let a = &mut A as *mut usize;
|
||||
let cur = a.read_volatile();
|
||||
for _ in 0..500 { t = t * t % 10007; }
|
||||
for _ in 0..500 {
|
||||
t = t * t % 10007;
|
||||
}
|
||||
a.write_volatile(cur + 1);
|
||||
// exit critical section
|
||||
OCCUPIED = false;
|
||||
|
@ -33,7 +37,7 @@ unsafe fn f() -> ! {
|
|||
#[no_mangle]
|
||||
pub fn main() -> i32 {
|
||||
let start = get_time();
|
||||
let mut v = Vec::new();
|
||||
let mut v = Vec::new();
|
||||
for _ in 0..THREAD_COUNT {
|
||||
v.push(thread_create(f as usize, 0) as usize);
|
||||
}
|
||||
|
|
|
@ -5,9 +5,9 @@
|
|||
extern crate user_lib;
|
||||
extern crate alloc;
|
||||
|
||||
use user_lib::{exit, thread_create, waittid, get_time};
|
||||
use user_lib::{mutex_blocking_create, mutex_lock, mutex_unlock};
|
||||
use alloc::vec::Vec;
|
||||
use user_lib::{exit, get_time, thread_create, waittid};
|
||||
use user_lib::{mutex_blocking_create, mutex_lock, mutex_unlock};
|
||||
|
||||
static mut A: usize = 0;
|
||||
const PER_THREAD: usize = 1000;
|
||||
|
@ -19,7 +19,9 @@ unsafe fn f() -> ! {
|
|||
mutex_lock(0);
|
||||
let a = &mut A as *mut usize;
|
||||
let cur = a.read_volatile();
|
||||
for _ in 0..500 { t = t * t % 10007; }
|
||||
for _ in 0..500 {
|
||||
t = t * t % 10007;
|
||||
}
|
||||
a.write_volatile(cur + 1);
|
||||
mutex_unlock(0);
|
||||
}
|
||||
|
@ -30,7 +32,7 @@ unsafe fn f() -> ! {
|
|||
pub fn main() -> i32 {
|
||||
let start = get_time();
|
||||
assert_eq!(mutex_blocking_create(), 0);
|
||||
let mut v = Vec::new();
|
||||
let mut v = Vec::new();
|
||||
for _ in 0..THREAD_COUNT {
|
||||
v.push(thread_create(f as usize, 0) as usize);
|
||||
}
|
||||
|
|
|
@ -5,9 +5,9 @@
|
|||
extern crate user_lib;
|
||||
extern crate alloc;
|
||||
|
||||
use user_lib::{exit, thread_create, waittid, get_time};
|
||||
use user_lib::{mutex_create, mutex_lock, mutex_unlock};
|
||||
use alloc::vec::Vec;
|
||||
use user_lib::{exit, get_time, thread_create, waittid};
|
||||
use user_lib::{mutex_create, mutex_lock, mutex_unlock};
|
||||
|
||||
static mut A: usize = 0;
|
||||
const PER_THREAD: usize = 1000;
|
||||
|
@ -19,7 +19,9 @@ unsafe fn f() -> ! {
|
|||
mutex_lock(0);
|
||||
let a = &mut A as *mut usize;
|
||||
let cur = a.read_volatile();
|
||||
for _ in 0..500 { t = t * t % 10007; }
|
||||
for _ in 0..500 {
|
||||
t = t * t % 10007;
|
||||
}
|
||||
a.write_volatile(cur + 1);
|
||||
mutex_unlock(0);
|
||||
}
|
||||
|
@ -30,7 +32,7 @@ unsafe fn f() -> ! {
|
|||
pub fn main() -> i32 {
|
||||
let start = get_time();
|
||||
assert_eq!(mutex_create(), 0);
|
||||
let mut v = Vec::new();
|
||||
let mut v = Vec::new();
|
||||
for _ in 0..THREAD_COUNT {
|
||||
v.push(thread_create(f as usize, 0) as usize);
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#[macro_use]
|
||||
extern crate user_lib;
|
||||
|
||||
use user_lib::{fork, exec, wait};
|
||||
use user_lib::{exec, fork, wait};
|
||||
|
||||
#[no_mangle]
|
||||
pub fn main() -> i32 {
|
||||
|
|
|
@ -4,10 +4,10 @@
|
|||
#[macro_use]
|
||||
extern crate user_lib;
|
||||
|
||||
use user_lib::{sleep, exit, get_time, fork, waitpid};
|
||||
use user_lib::{exit, fork, get_time, sleep, waitpid};
|
||||
|
||||
fn sleepy() {
|
||||
let time: usize = 1000;
|
||||
let time: usize = 100;
|
||||
for i in 0..5 {
|
||||
sleep(time);
|
||||
println!("sleep {} x {} msecs.", i + 1, time);
|
||||
|
@ -27,4 +27,4 @@ pub fn main() -> i32 {
|
|||
println!("use {} msecs.", get_time() - current_time);
|
||||
println!("sleep pass.");
|
||||
0
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,11 @@ pub fn main() -> i32 {
|
|||
println!("current time_msec = {}", start);
|
||||
sleep(100);
|
||||
let end = get_time();
|
||||
println!("time_msec = {} after sleeping 100 ticks, delta = {}ms!", end, end - start);
|
||||
println!(
|
||||
"time_msec = {} after sleeping 100 ticks, delta = {}ms!",
|
||||
end,
|
||||
end - start
|
||||
);
|
||||
println!("r_sleep passed!");
|
||||
0
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
extern crate user_lib;
|
||||
|
||||
fn f(d: usize) {
|
||||
println!("d = {}",d);
|
||||
println!("d = {}", d);
|
||||
f(d + 1);
|
||||
}
|
||||
|
||||
|
@ -14,4 +14,4 @@ pub fn main() -> i32 {
|
|||
println!("It should trigger segmentation fault!");
|
||||
f(0);
|
||||
0
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,14 +6,13 @@ extern crate user_lib;
|
|||
|
||||
extern crate alloc;
|
||||
|
||||
use user_lib::{semaphore_create, semaphore_up, semaphore_down};
|
||||
use user_lib::{thread_create, waittid, sleep};
|
||||
use user_lib::exit;
|
||||
use alloc::vec;
|
||||
use user_lib::exit;
|
||||
use user_lib::{semaphore_create, semaphore_down, semaphore_up};
|
||||
use user_lib::{sleep, thread_create, waittid};
|
||||
|
||||
const SEM_SYNC: usize = 0;
|
||||
|
||||
|
||||
unsafe fn first() -> ! {
|
||||
sleep(10);
|
||||
println!("First work and wakeup Second");
|
||||
|
|
|
@ -6,10 +6,12 @@ extern crate user_lib;
|
|||
|
||||
extern crate alloc;
|
||||
|
||||
use user_lib::{condvar_create, condvar_signal, condvar_wait, mutex_blocking_create, mutex_lock, mutex_unlock};
|
||||
use user_lib::{thread_create, waittid, sleep};
|
||||
use user_lib::exit;
|
||||
use alloc::vec;
|
||||
use user_lib::exit;
|
||||
use user_lib::{
|
||||
condvar_create, condvar_signal, condvar_wait, mutex_blocking_create, mutex_lock, mutex_unlock,
|
||||
};
|
||||
use user_lib::{sleep, thread_create, waittid};
|
||||
|
||||
static mut A: usize = 0;
|
||||
|
||||
|
@ -20,7 +22,7 @@ unsafe fn first() -> ! {
|
|||
sleep(10);
|
||||
println!("First work, Change A --> 1 and wakeup Second");
|
||||
mutex_lock(MUTEX_ID);
|
||||
A=1;
|
||||
A = 1;
|
||||
condvar_signal(CONDVAR_ID);
|
||||
mutex_unlock(MUTEX_ID);
|
||||
exit(0)
|
||||
|
@ -29,7 +31,7 @@ unsafe fn first() -> ! {
|
|||
unsafe fn second() -> ! {
|
||||
println!("Second want to continue,but need to wait A=1");
|
||||
mutex_lock(MUTEX_ID);
|
||||
while A==0 {
|
||||
while A == 0 {
|
||||
println!("Second: A is {}", A);
|
||||
condvar_wait(CONDVAR_ID, MUTEX_ID);
|
||||
}
|
||||
|
|
|
@ -5,21 +5,27 @@
|
|||
extern crate user_lib;
|
||||
extern crate alloc;
|
||||
|
||||
use user_lib::{thread_create, waittid, exit};
|
||||
use alloc::vec;
|
||||
use user_lib::{exit, thread_create, waittid};
|
||||
|
||||
pub fn thread_a() -> ! {
|
||||
for _ in 0..1000 { print!("a"); }
|
||||
for _ in 0..1000 {
|
||||
print!("a");
|
||||
}
|
||||
exit(1)
|
||||
}
|
||||
|
||||
pub fn thread_b() -> ! {
|
||||
for _ in 0..1000 { print!("b"); }
|
||||
exit(2)
|
||||
for _ in 0..1000 {
|
||||
print!("b");
|
||||
}
|
||||
exit(2)
|
||||
}
|
||||
|
||||
pub fn thread_c() -> ! {
|
||||
for _ in 0..1000 { print!("c"); }
|
||||
for _ in 0..1000 {
|
||||
print!("c");
|
||||
}
|
||||
exit(3)
|
||||
}
|
||||
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
extern crate user_lib;
|
||||
extern crate alloc;
|
||||
|
||||
use user_lib::{thread_create, waittid, exit};
|
||||
use alloc::vec::Vec;
|
||||
use user_lib::{exit, thread_create, waittid};
|
||||
|
||||
struct Argument {
|
||||
pub ch: char,
|
||||
|
@ -15,7 +15,9 @@ struct Argument {
|
|||
|
||||
fn thread_print(arg: *const Argument) -> ! {
|
||||
let arg = unsafe { &*arg };
|
||||
for _ in 0..1000 { print!("{}", arg.ch); }
|
||||
for _ in 0..1000 {
|
||||
print!("{}", arg.ch);
|
||||
}
|
||||
exit(arg.rc)
|
||||
}
|
||||
|
||||
|
@ -23,12 +25,15 @@ fn thread_print(arg: *const Argument) -> ! {
|
|||
pub fn main() -> i32 {
|
||||
let mut v = Vec::new();
|
||||
let args = [
|
||||
Argument { ch: 'a', rc: 1, },
|
||||
Argument { ch: 'b', rc: 2, },
|
||||
Argument { ch: 'c', rc: 3, },
|
||||
];
|
||||
Argument { ch: 'a', rc: 1 },
|
||||
Argument { ch: 'b', rc: 2 },
|
||||
Argument { ch: 'c', rc: 3 },
|
||||
];
|
||||
for arg in args.iter() {
|
||||
v.push(thread_create(thread_print as usize, arg as *const _ as usize));
|
||||
v.push(thread_create(
|
||||
thread_print as usize,
|
||||
arg as *const _ as usize,
|
||||
));
|
||||
}
|
||||
for tid in v.iter() {
|
||||
let exit_code = waittid(*tid as usize);
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![allow(clippy::println_empty_string)]
|
||||
|
@ -213,4 +212,3 @@ pub fn main() -> i32 {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -32,7 +32,10 @@ pub fn main() -> i32 {
|
|||
let mut exit_code: i32 = Default::default();
|
||||
let wait_pid = waitpid(pid as usize, &mut exit_code);
|
||||
assert_eq!(pid, wait_pid);
|
||||
println!("\x1b[32mUsertests: Test {} in Process {} exited with code {}\x1b[0m", test, pid, exit_code);
|
||||
println!(
|
||||
"\x1b[32mUsertests: Test {} in Process {} exited with code {}\x1b[0m",
|
||||
test, pid, exit_code
|
||||
);
|
||||
}
|
||||
}
|
||||
println!("Usertests passed!");
|
||||
|
|
|
@ -14,4 +14,4 @@ pub fn main() -> i32 {
|
|||
}
|
||||
println!("yield pass.");
|
||||
0
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,9 +4,14 @@ use super::exit;
|
|||
fn panic_handler(panic_info: &core::panic::PanicInfo) -> ! {
|
||||
let err = panic_info.message().unwrap();
|
||||
if let Some(location) = panic_info.location() {
|
||||
println!("Panicked at {}:{}, {}", location.file(), location.line(), err);
|
||||
println!(
|
||||
"Panicked at {}:{}, {}",
|
||||
location.file(),
|
||||
location.line(),
|
||||
err
|
||||
);
|
||||
} else {
|
||||
println!("Panicked: {}", err);
|
||||
}
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,7 +58,10 @@ pub fn sys_pipe(pipe: &mut [usize]) -> isize {
|
|||
}
|
||||
|
||||
pub fn sys_read(fd: usize, buffer: &mut [u8]) -> isize {
|
||||
syscall(SYSCALL_READ, [fd, buffer.as_mut_ptr() as usize, buffer.len()])
|
||||
syscall(
|
||||
SYSCALL_READ,
|
||||
[fd, buffer.as_mut_ptr() as usize, buffer.len()],
|
||||
)
|
||||
}
|
||||
|
||||
pub fn sys_write(fd: usize, buffer: &[u8]) -> isize {
|
||||
|
@ -91,7 +94,10 @@ pub fn sys_fork() -> isize {
|
|||
}
|
||||
|
||||
pub fn sys_exec(path: &str, args: &[*const u8]) -> isize {
|
||||
syscall(SYSCALL_EXEC, [path.as_ptr() as usize, args.as_ptr() as usize, 0])
|
||||
syscall(
|
||||
SYSCALL_EXEC,
|
||||
[path.as_ptr() as usize, args.as_ptr() as usize, 0],
|
||||
)
|
||||
}
|
||||
|
||||
pub fn sys_waitpid(pid: isize, exit_code: *mut i32) -> isize {
|
||||
|
@ -142,6 +148,6 @@ pub fn sys_condvar_signal(condvar_id: usize) -> isize {
|
|||
syscall(SYSCALL_CONDVAR_SIGNAL, [condvar_id, 0, 0])
|
||||
}
|
||||
|
||||
pub fn sys_condvar_wait(condvar_id: usize, mutex_id:usize) -> isize {
|
||||
pub fn sys_condvar_wait(condvar_id: usize, mutex_id: usize) -> isize {
|
||||
syscall(SYSCALL_CONDVAR_WAIT, [condvar_id, mutex_id, 0])
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue