Skip to content

Commit

Permalink
okok
Browse files Browse the repository at this point in the history
  • Loading branch information
fasterthanlime committed Jul 18, 2024
1 parent e62b3f1 commit 4b9262b
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 16 deletions.
10 changes: 9 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,12 @@ jobs:
profile: minimal
override: true
- name: Run cargo command
run: cargo run --manifest-path test-crates/bin/Cargo.toml
run: |
cargo run --manifest-path test-crates/bin/Cargo.toml
- name: Run cargo command (release)
run: |
cargo run --manifest-path test-crates/bin/Cargo.toml --release
- name: Run cargo command (release with SOPRINTLN=1)
run: |
export SOPRINTLN=1
cargo run --manifest-path test-crates/bin/Cargo.toml --release
9 changes: 2 additions & 7 deletions test-crates/bin/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,6 @@ fn main() {
let init_b: libloading::Symbol<unsafe extern "C" fn()> = unsafe { lib_b.get(b"init").unwrap() };
let init_b = Box::leak(Box::new(init_b));

soprintln!("DANGEROUS is now {}", unsafe {
mokio::DANGEROUS += 1;
mokio::DANGEROUS
});

soprintln!(
"PL1 = {}, TL1 = {} (initial)",
mokio::MOKIO_PL1.load(Ordering::Relaxed),
Expand Down Expand Up @@ -153,6 +148,6 @@ fn main() {
// 2 per turn, 2 turns on the main thread, 2 turns on each of the 3 worker threads: 16 total
assert_eq!(mokio::MOKIO_PL1.load(Ordering::Relaxed), 16);

// DANGEROUS should be between 1 and 20
assert!(unsafe { mokio::DANGEROUS } >= 1 && unsafe { mokio::DANGEROUS } <= 20);
// same for DANGEROUS, it's just guarded by a mutex internally
assert_eq!(mokio::get_dangerous(), 16);
}
7 changes: 3 additions & 4 deletions test-crates/mod_a/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ pub fn init() {
soprintln::init!();
mokio::MOKIO_TL1.with(|s| s.fetch_add(1, Ordering::Relaxed));
mokio::MOKIO_PL1.fetch_add(1, Ordering::Relaxed);
soprintln!("DANGEROUS is now {}", unsafe {
mokio::DANGEROUS += 1;
mokio::DANGEROUS
});

let dangerous = mokio::inc_dangerous();
soprintln!("DANGEROUS is now {}", dangerous);
}
7 changes: 3 additions & 4 deletions test-crates/mod_b/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ pub fn init() {
soprintln::init!();
mokio::MOKIO_TL1.with(|s| s.fetch_add(1, Ordering::Relaxed));
mokio::MOKIO_PL1.fetch_add(1, Ordering::Relaxed);
soprintln!("DANGEROUS is now {}", unsafe {
mokio::DANGEROUS += 1;
mokio::DANGEROUS
});

let dangerous = mokio::inc_dangerous();
soprintln!("DANGEROUS is now {}", dangerous);
}
15 changes: 15 additions & 0 deletions test-crates/mokio/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,25 @@ use std::sync::atomic::AtomicU64;
rubicon::process_local! {
pub static MOKIO_PL1: AtomicU64 = AtomicU64::new(0);
pub static MOKIO_PL2: AtomicU64 = AtomicU64::new(0);

pub static mut DANGEROUS: u64 = 0;
static DANGEROUS_MUTEX: std::sync::Mutex<()> = std::sync::Mutex::new(());
}

rubicon::thread_local! {
pub static MOKIO_TL1: AtomicU64 = AtomicU64::new(0);
pub static MOKIO_TL2: AtomicU64 = AtomicU64::new(0);
}

pub fn inc_dangerous() -> u64 {
let _guard = DANGEROUS_MUTEX.lock().unwrap();
unsafe {
DANGEROUS += 1;
DANGEROUS
}
}

pub fn get_dangerous() -> u64 {
let _guard = DANGEROUS_MUTEX.lock().unwrap();
unsafe { DANGEROUS }
}

0 comments on commit 4b9262b

Please sign in to comment.