final fixes

This commit is contained in:
Ashwin Naren
2025-12-20 15:46:51 -08:00
parent d60e70e397
commit a6efc75686
2 changed files with 5 additions and 33 deletions

View File

@@ -66,6 +66,8 @@ pub async fn sys_set_robust_list(head: TUA<RobustListHead>, len: usize) -> Resul
const FUTEX_WAIT: i32 = 0;
const FUTEX_WAKE: i32 = 1;
const FUTEX_WAIT_BITSET: i32 = 9;
const FUTEX_WAKE_BITSET: i32 = 10;
const FUTEX_PRIVATE_FLAG: i32 = 128;
pub async fn sys_futex(
@@ -80,7 +82,7 @@ pub async fn sys_futex(
let cmd = op & !FUTEX_PRIVATE_FLAG;
match cmd {
FUTEX_WAIT => {
FUTEX_WAIT | FUTEX_WAIT_BITSET => {
// Ensure the wait-queue exists *before* we begin checking the
// futex word so that a racing FUTEX_WAKE cannot miss us. This
// avoids the classic lost-wake-up race where a waker runs between
@@ -128,7 +130,7 @@ pub async fn sys_futex(
Ok(0)
}
FUTEX_WAKE => {
FUTEX_WAKE | FUTEX_WAKE_BITSET => {
let nr_wake = val as usize;
let mut woke = 0;

View File

@@ -157,6 +157,7 @@ fn test_rust_mutex() {
let mtx_clone = Arc::clone(&mutex);
let mut num = mtx_clone.lock().unwrap();
*num += 1;
drop(num);
let final_count = *mutex.lock().unwrap();
if final_count != 1 {
panic!("Mutex test failed, expected 1 but got {}", final_count);
@@ -164,36 +165,6 @@ fn test_rust_mutex() {
println!(" OK");
}
fn test_rust_mutex_contention() {
use std::sync::{Arc, Mutex};
use std::thread;
print!("Testing Rust Mutex w/contention ...");
let mutex = Arc::new(Mutex::new(0));
let mut handles = vec![];
for _ in 0..10 {
let mtx_clone = Arc::clone(&mutex);
let handle = thread::spawn(move || {
for _ in 0..1000 {
let mut num = mtx_clone.lock().unwrap();
*num += 1;
}
});
handles.push(handle);
}
for handle in handles {
handle.join().unwrap();
}
let final_count = *mutex.lock().unwrap();
if final_count != 10_000 {
panic!("Mutex test failed, expected 10000 but got {}", final_count);
}
println!(" OK");
}
fn test_rust_file() {
print!("Testing rust file operations ...");
use std::fs::{self, File};
@@ -261,7 +232,6 @@ fn main() {
run_test(test_write);
run_test(test_futex);
run_test(test_rust_mutex);
run_test(test_rust_mutex_contention);
run_test(test_rust_file);
run_test(test_rust_dir);
let end = std::time::Instant::now();