main thread in browser can't execute parking - so we use parking lot in spin-lock style for that target

This commit is contained in:
Nikita Sivukhin
2025-09-18 01:35:22 +04:00
parent 1d3c823c7b
commit b106220743

View File

@@ -1639,11 +1639,41 @@ impl WalFile {
}
fn get_shared_mut(&self) -> parking_lot::RwLockWriteGuard<'_, WalFileShared> {
self.shared.write()
// WASM in browser main thread doesn't have a way to "park" a thread
// so, we spin way here instead of calling blocking lock
#[cfg(target_family = "wasm")]
{
loop {
let Some(lock) = self.shared.try_write() else {
std::hint::spin_loop();
continue;
};
return lock;
}
}
#[cfg(not(target_family = "wasm"))]
{
self.shared.write()
}
}
fn get_shared(&self) -> parking_lot::RwLockReadGuard<'_, WalFileShared> {
self.shared.read()
// WASM in browser main thread doesn't have a way to "park" a thread
// so, we spin way here instead of calling blocking lock
#[cfg(target_family = "wasm")]
{
loop {
let Some(lock) = self.shared.try_read() else {
std::hint::spin_loop();
continue;
};
return lock;
}
}
#[cfg(not(target_family = "wasm"))]
{
self.shared.read()
}
}
fn complete_append_frame(&mut self, page_id: u64, frame_id: u64, checksums: (u32, u32)) {