Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/bin/ch7b_pipe_large_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ extern crate user_lib;
extern crate alloc;

use alloc::format;
use user_lib::{close, fork, get_time, pipe, read, wait, write,getpid};
use user_lib::{close, fork, pipe, read, wait, write,getpid};

const LENGTH: usize = 3000;
#[no_mangle]
Expand Down
3 changes: 2 additions & 1 deletion src/bin/ch8b_race_adder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ extern crate user_lib;
extern crate alloc;

use alloc::vec::Vec;
use core::ptr::addr_of_mut;
use user_lib::{exit, get_time, thread_create, waittid};

static mut A: usize = 0;
Expand All @@ -15,7 +16,7 @@ const THREAD_COUNT: usize = 16;
unsafe fn f() -> ! {
let mut t = 2usize;
for _ in 0..PER_THREAD {
let a = &mut A as *mut usize;
let a = addr_of_mut!(A) as *mut usize;
let cur = a.read_volatile();
for _ in 0..500 {
t = t * t % 10007;
Expand Down
3 changes: 2 additions & 1 deletion src/bin/ch8b_race_adder_atomic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ extern crate user_lib;
extern crate alloc;

use alloc::vec::Vec;
use core::ptr::addr_of_mut;
use core::sync::atomic::{AtomicBool, Ordering};
use user_lib::{exit, get_time, thread_create, waittid, yield_};

Expand All @@ -23,7 +24,7 @@ unsafe fn f() -> ! {
{
yield_();
}
let a = &mut A as *mut usize;
let a = addr_of_mut!(A) as *mut usize;
let cur = a.read_volatile();
for _ in 0..500 {
t = t * t % 10007;
Expand Down
5 changes: 3 additions & 2 deletions src/bin/ch8b_race_adder_loop.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#![no_std]
#![no_main]

extern crate alloc;
#[macro_use]
extern crate user_lib;
extern crate alloc;

use alloc::vec::Vec;
use core::ptr::addr_of_mut;
use user_lib::{exit, get_time, thread_create, waittid, yield_};

static mut A: usize = 0;
Expand All @@ -21,7 +22,7 @@ unsafe fn f() -> ! {
}
OCCUPIED = true;
// enter critical section
let a = &mut A as *mut usize;
let a = addr_of_mut!(A) as *mut usize;
let cur = a.read_volatile();
for _ in 0..500 {
t = t * t % 10007;
Expand Down
3 changes: 2 additions & 1 deletion src/bin/ch8b_race_adder_mutex_spin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ extern crate user_lib;
extern crate alloc;

use alloc::vec::Vec;
use core::ptr::addr_of_mut;
use user_lib::{exit, get_time, thread_create, waittid};
use user_lib::{mutex_create, mutex_lock, mutex_unlock};

Expand All @@ -17,7 +18,7 @@ unsafe fn f() -> ! {
let mut t = 2usize;
for _ in 0..PER_THREAD {
mutex_lock(0);
let a = &mut A as *mut usize;
let a = addr_of_mut!(A) as *mut usize;
let cur = a.read_volatile();
for _ in 0..500 {
t = t * t % 10007;
Expand Down
3 changes: 2 additions & 1 deletion src/bin/ch8b_stackful_coroutine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ enum State {
}

struct Task {
#[allow(dead_code)]
id: usize,
stack: Vec<u8>,
ctx: TaskContext,
Expand Down Expand Up @@ -256,7 +257,7 @@ pub fn yield_task() {
/// see: https://doc.rust-lang.org/nightly/rust-by-example/unsafe/asm.html
#[naked]
#[no_mangle]
unsafe fn switch(old: *mut TaskContext, new: *const TaskContext) {
unsafe extern "C" fn switch(old: *mut TaskContext, new: *const TaskContext) {
// a0: _old, a1: _new
asm!(
"
Expand Down