implement clone on the sync primitives

This commit is contained in:
Garen Tyler 2023-11-09 22:18:09 -07:00
parent 765598c80c
commit f3e31d869a
Signed by: garentyler
GPG Key ID: D7A048C454CB7054
4 changed files with 28 additions and 0 deletions

View File

@ -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> {

View File

@ -42,6 +42,12 @@ impl<T> Mutex<T> {
}
}
unsafe impl<T> Sync for Mutex<T> where T: Send {}
impl<T> Clone for Mutex<T> 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<T>,

View File

@ -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,

View File

@ -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,