user: add peterson algorithm and Eisenberg & McGuire algorithm

This commit is contained in:
DeathWish5 2021-12-22 23:35:34 +08:00
parent 28a0eaf045
commit ef3f87d31b
3 changed files with 194 additions and 0 deletions

View file

@ -3,6 +3,7 @@
#![feature(linkage)]
#![feature(panic_info_message)]
#![feature(alloc_error_handler)]
#![feature(core_intrinsics)]
#[macro_use]
pub mod console;
@ -129,3 +130,23 @@ pub fn semaphore_down(sem_id: usize) {
sys_semaphore_down(sem_id);
}
#[macro_export]
macro_rules! store {
($var_ref: expr, $value: expr) => {
unsafe { core::intrinsics::volatile_store($var_ref as *const _ as _, $value) }
};
}
#[macro_export]
macro_rules! load {
($var_ref: expr) => {
unsafe { core::intrinsics::volatile_load($var_ref as *const _ as _) }
};
}
#[macro_export]
macro_rules! memory_fence {
() => {
core::sync::atomic::fence(core::sync::atomic::Ordering::SeqCst)
};
}