Skip to content

Commit

Permalink
Mark libc's `fs::Dir as Sync (#1232)
Browse files Browse the repository at this point in the history
This is safe since all methods that mutate the internal state require
a &mut self. It also makes behavior consistent with the linux_raw
backend (whose `fs::Dir` is Sync+Send).

Fixes: #1230.
  • Loading branch information
nrath-js authored Dec 8, 2024
1 parent 73e82e2 commit 5a012c8
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/backend/libc/fs/dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,11 +227,12 @@ impl Dir {
}
}

/// `Dir` implements `Send` but not `Sync`, because we use `readdir` which is
/// not guaranteed to be thread-safe. Users can wrap this in a `Mutex` if they
/// need `Sync`, which is effectively what'd need to do to implement `Sync`
/// ourselves.
/// `Dir` is `Send` and `Sync`, because even though it contains internal
/// state, all methods that modify the state require a `mut &self` and
/// can therefore not be called concurrently. Calling them from different
/// threads sequentially is fine.
unsafe impl Send for Dir {}
unsafe impl Sync for Dir {}

impl Drop for Dir {
#[inline]
Expand Down

0 comments on commit 5a012c8

Please sign in to comment.