This commit is contained in:
parent
311755c812
commit
baa6c1568e
30 changed files with 181 additions and 108 deletions
|
|
@ -50,7 +50,7 @@ impl<T> DerefMut for MutexGuard<'_, T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T> Mutex<T> {
|
||||
impl<'a, T> Mutex<T> {
|
||||
pub fn new(data: T) -> Mutex<T> {
|
||||
Mutex {
|
||||
cap: syscall::mutex_create().unwrap(),
|
||||
|
|
@ -58,7 +58,7 @@ impl<T> Mutex<T> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn lock(&self) -> MutexGuard<T> {
|
||||
pub fn lock(&'a self) -> MutexGuard<'a, T> {
|
||||
syscall::mutex_lock(&self.cap).unwrap();
|
||||
|
||||
MutexGuard { mutex: self }
|
||||
|
|
@ -70,3 +70,12 @@ impl<T> Drop for MutexGuard<'_, T> {
|
|||
syscall::mutex_release(&self.mutex.cap).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Default for Mutex<T>
|
||||
where
|
||||
T: Default,
|
||||
{
|
||||
fn default() -> Self {
|
||||
Self::new(T::default())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue