From 08d2289dad5be8862392ec191c5bc2f71a3139b5 Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Thu, 9 Jan 2020 15:34:04 +0100 Subject: [PATCH] Add a `Locked` wrapper type that can be used to implement GlobalAlloc --- src/allocator.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/allocator.rs b/src/allocator.rs index 4b683208..a52744f4 100644 --- a/src/allocator.rs +++ b/src/allocator.rs @@ -54,3 +54,20 @@ unsafe impl GlobalAlloc for Dummy { panic!("dealloc should be never called") } } + +/// A wrapper around spin::Mutex to permit trait implementations. +pub struct Locked { + inner: spin::Mutex, +} + +impl Locked { + pub const fn new(inner: A) -> Self { + Locked { + inner: spin::Mutex::new(inner), + } + } + + pub fn lock(&self) -> spin::MutexGuard { + self.inner.lock() + } +}