Skip to content

Commit

Permalink
Merge pull request #1066 from mkroening/min-mem-locking
Browse files Browse the repository at this point in the history
perf(fs/mem): minimize locking duration of pos
  • Loading branch information
mkroening authored Feb 14, 2024
2 parents 938bf3a + c59d822 commit 3d3299f
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/fs/mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ impl ObjectInterface for RomFileInterface {
async fn poll(&self, event: PollEvent) -> Result<PollEvent, IoError> {
let mut result: PollEvent = PollEvent::empty();
let len = self.inner.read().await.data.len();
let pos_guard = self.pos.lock().await;
let pos = *pos_guard;
let pos = *self.pos.lock().await;

if event.contains(PollEvent::POLLIN) && pos < len {
result.insert(PollEvent::POLLIN);
Expand Down Expand Up @@ -138,8 +137,7 @@ impl ObjectInterface for RamFileInterface {
async fn poll(&self, event: PollEvent) -> Result<PollEvent, IoError> {
let mut result: PollEvent = PollEvent::empty();
let len = self.inner.read().await.data.len();
let pos_guard = self.pos.lock().await;
let pos = *pos_guard;
let pos = *self.pos.lock().await;

if event.contains(PollEvent::POLLIN) && pos < len {
result.insert(PollEvent::POLLIN);
Expand Down

0 comments on commit 3d3299f

Please sign in to comment.