Skip to content

Commit

Permalink
use upgradable lock in SHM mappings
Browse files Browse the repository at this point in the history
  • Loading branch information
yellowhatter committed Sep 19, 2023
1 parent 8959f4d commit 2aacf64
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions io/zenoh-transport/src/shm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@
// Contributors:
// ZettaScale Zenoh Team, <[email protected]>
//
use async_std::{sync::RwLock, task};
use async_std::{
sync::{RwLock, RwLockUpgradableReadGuard},
task,
};
use zenoh_buffers::{reader::HasReader, writer::HasWriter, ZBuf, ZSlice, ZSliceKind};
use zenoh_codec::{RCodec, WCodec, Zenoh080};
use zenoh_core::{zasyncread, zasyncwrite, zerror};
use zenoh_core::{zasyncread_upgradable, zerror};
use zenoh_protocol::{
network::{NetworkBody, NetworkMessage, Push, Request, Response},
zenoh::{
Expand Down Expand Up @@ -249,10 +252,9 @@ pub fn map_zslice_to_shmbuf(
let shmbinfo: SharedMemoryBufInfo = codec.read(&mut reader).map_err(|e| zerror!("{:?}", e))?;

// First, try in read mode allowing concurrenct lookups
let r_guard = task::block_on(async { zasyncread!(shmr) });
let r_guard = task::block_on(async { zasyncread_upgradable!(shmr) });
let smb = r_guard.try_read_shmbuf(&shmbinfo).or_else(|_| {
drop(r_guard);
let mut w_guard = task::block_on(async { zasyncwrite!(shmr) });
let mut w_guard = task::block_on(RwLockUpgradableReadGuard::upgrade(r_guard));
w_guard.read_shmbuf(&shmbinfo)
})?;

Expand Down

0 comments on commit 2aacf64

Please sign in to comment.