Skip to content

Commit 4046ed7

Browse files
nrath-jssunfishcode
authored andcommitted
Mark libc's `fs::Dir as Sync (#1232)
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.
1 parent a7ba1b8 commit 4046ed7

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/backend/libc/fs/dir.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -227,11 +227,12 @@ impl Dir {
227227
}
228228
}
229229

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

236237
impl Drop for Dir {
237238
#[inline]

0 commit comments

Comments
 (0)