Skip to content

Commit 22d07a0

Browse files
committed
Add Sync impl for spinlock/mutex guards.
1 parent 5e43f98 commit 22d07a0

File tree

4 files changed

+8
-0
lines changed

4 files changed

+8
-0
lines changed

src/ch4_spin_lock/s3_guard.rs

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ pub struct Guard<'a, T> {
1414
lock: &'a SpinLock<T>,
1515
}
1616

17+
unsafe impl<T> Sync for Guard<'_, T> where T: Sync {}
18+
1719
impl<T> SpinLock<T> {
1820
pub const fn new(value: T) -> Self {
1921
Self {

src/ch9_locks/mutex_1.rs

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ pub struct MutexGuard<'a, T> {
1717
mutex: &'a Mutex<T>,
1818
}
1919

20+
unsafe impl<T> Sync for MutexGuard<'_, T> where T: Sync {}
21+
2022
impl<T> Deref for MutexGuard<'_, T> {
2123
type Target = T;
2224
fn deref(&self) -> &T {

src/ch9_locks/mutex_2.rs

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ pub struct MutexGuard<'a, T> {
1818
mutex: &'a Mutex<T>,
1919
}
2020

21+
unsafe impl<T> Sync for MutexGuard<'_, T> where T: Sync {}
22+
2123
impl<T> Deref for MutexGuard<'_, T> {
2224
type Target = T;
2325
fn deref(&self) -> &T {

src/ch9_locks/mutex_3.rs

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ pub struct MutexGuard<'a, T> {
1818
pub(crate) mutex: &'a Mutex<T>,
1919
}
2020

21+
unsafe impl<T> Sync for MutexGuard<'_, T> where T: Sync {}
22+
2123
impl<T> Deref for MutexGuard<'_, T> {
2224
type Target = T;
2325
fn deref(&self) -> &T {

0 commit comments

Comments
 (0)