diff --git a/kernel/rustkernel/src/sync/lock.rs b/kernel/rustkernel/src/sync/lock.rs index d78a235..1b024d3 100644 --- a/kernel/rustkernel/src/sync/lock.rs +++ b/kernel/rustkernel/src/sync/lock.rs @@ -77,6 +77,14 @@ impl Default for Lock { Lock::new() } } +impl Clone for Lock { + fn clone(&self) -> Self { + Lock { + locked: AtomicBool::new(self.locked.load(Ordering::SeqCst)), + lock_strategy: UnsafeCell::new(self.lock_strategy()), + } + } +} unsafe impl Sync for Lock {} pub struct LockGuard<'l> { diff --git a/kernel/rustkernel/src/sync/mutex.rs b/kernel/rustkernel/src/sync/mutex.rs index 952f877..645323f 100644 --- a/kernel/rustkernel/src/sync/mutex.rs +++ b/kernel/rustkernel/src/sync/mutex.rs @@ -42,6 +42,12 @@ impl Mutex { } } unsafe impl Sync for Mutex where T: Send {} +impl Clone for Mutex where T: Clone { + fn clone(&self) -> Self { + let value: T = self.lock_spinning().as_ref().clone(); + Mutex::new(value) + } +} pub struct MutexGuard<'m, T> { pub mutex: &'m Mutex, diff --git a/kernel/rustkernel/src/sync/sleeplock.rs b/kernel/rustkernel/src/sync/sleeplock.rs index 101fc9f..e8e9c4e 100644 --- a/kernel/rustkernel/src/sync/sleeplock.rs +++ b/kernel/rustkernel/src/sync/sleeplock.rs @@ -34,6 +34,13 @@ impl Sleeplock { wakeup(addr_of!(*self).cast_mut().cast()); } } +impl Clone for Sleeplock { + fn clone(&self) -> Self { + Sleeplock { + locked: AtomicBool::new(self.locked.load(Ordering::SeqCst)), + } + } +} pub struct SleeplockGuard<'l> { pub lock: &'l Sleeplock, diff --git a/kernel/rustkernel/src/sync/spinlock.rs b/kernel/rustkernel/src/sync/spinlock.rs index 1c8a316..6668617 100644 --- a/kernel/rustkernel/src/sync/spinlock.rs +++ b/kernel/rustkernel/src/sync/spinlock.rs @@ -42,6 +42,13 @@ impl Spinlock { pop_intr_off(); } } +impl Clone for Spinlock { + fn clone(&self) -> Self { + Spinlock { + locked: AtomicBool::new(self.locked.load(Ordering::SeqCst)), + } + } +} pub struct SpinlockGuard<'l> { pub lock: &'l Spinlock,