Skip to content

Commit fdc9307

Browse files
committed
feat(sync): make small changes to constance::sync::Mutex
- `Mutex` now implements `Send` and `Sync` when it's appropriate to do so - `MutexGuard` now has `#[must_use]` like `std::sync::MutexGuard` does - The error types now implement `Debug`
1 parent a733c16 commit fdc9307

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/constance/src/sync/mutex.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ pub struct Mutex<System, T> {
2222
_phantom: PhantomData<(System, T)>,
2323
}
2424

25+
unsafe impl<System: Kernel, T: 'static + Send> Send for Mutex<System, T> {}
26+
unsafe impl<System: Kernel, T: 'static + Send> Sync for Mutex<System, T> {}
27+
2528
/// An RAII implementation of a "scoped lock" of a mutex. When this structure
2629
/// is dropped, the lock will be released.
2730
///
@@ -30,6 +33,7 @@ pub struct Mutex<System, T> {
3033
///
3134
/// [`lock`]: Mutex::lock
3235
/// [`try_lock`]: Mutex::try_lock
36+
#[must_use = "if unused the Mutex will immediately unlock"]
3337
pub struct MutexGuard<'a, System: Kernel, T: 'static> {
3438
mutex: &'a Mutex<System, T>,
3539
_no_send_sync: PhantomData<*mut ()>,
@@ -38,7 +42,7 @@ pub struct MutexGuard<'a, System: Kernel, T: 'static> {
3842
unsafe impl<System: Kernel, T: 'static + Sync> Sync for MutexGuard<'_, System, T> {}
3943

4044
/// Error type of [`Mutex::lock`].
41-
#[derive(Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
45+
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
4246
#[repr(i8)]
4347
pub enum LockError {
4448
/// CPU Lock is active, the current context is not [waitable], or the
@@ -54,7 +58,7 @@ pub enum LockError {
5458
}
5559

5660
/// Error type of [`Mutex::try_lock`].
57-
#[derive(Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
61+
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
5862
#[repr(i8)]
5963
pub enum TryLockError {
6064
/// CPU Lock is active.

0 commit comments

Comments
 (0)