diff --git a/src/lib.rs b/src/lib.rs index 039b18e73e272ebba862353422dcdb8ea8b9e28e..2efe511681e58d96e95d62cbe689106584922ced 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -32,10 +32,7 @@ pub unsafe trait Resource { fn borrow<'cs>(&'cs self, t: &'cs Threshold) -> &'cs Static<Self::Data>; /// Mutable variant of `borrow` - fn borrow_mut<'cs>( - &'cs mut self, - t: &'cs Threshold, - ) -> &'cs mut Static<Self::Data>; + fn borrow_mut<'cs>(&'cs mut self, t: &'cs Threshold) -> &'cs mut Static<Self::Data>; /// Claims the resource data for the span of the closure `f`. For the /// duration of the closure other tasks that may access the resource data @@ -48,6 +45,11 @@ pub unsafe trait Resource { fn claim_mut<R, F>(&mut self, t: &mut Threshold, f: F) -> R where F: FnOnce(&mut Static<Self::Data>, &mut Threshold) -> R; + + /// New Mutable variant of `claim` + fn claim_mut_new<R, F>(&mut self, b: &mut bool, t: &mut Threshold, f: F) -> R + where + F: FnOnce(&mut Static<Self::Data>, &mut bool, &mut Threshold) -> R; } unsafe impl<T> Resource for Static<T> @@ -60,10 +62,7 @@ where self } - fn borrow_mut<'cs>( - &'cs mut self, - _cs: &'cs Threshold, - ) -> &'cs mut Static<T> { + fn borrow_mut<'cs>(&'cs mut self, _cs: &'cs Threshold) -> &'cs mut Static<T> { self } @@ -80,6 +79,13 @@ where { f(self, t) } + + fn claim_mut_new<R, F>(&mut self, b: &mut bool, t: &mut Threshold, f: F) -> R + where + F: FnOnce(&mut Static<Self::Data>, &mut bool, &mut Threshold) -> R, + { + f(self, b, t) + } } /// Preemption threshold token @@ -99,7 +105,10 @@ impl Threshold { /// This API is meant to be used to create abstractions and not to be /// directly used by applications. pub unsafe fn new(value: u8) -> Self { - Threshold { value, _not_send: PhantomData } + Threshold { + value, + _not_send: PhantomData, + } } /// Creates a `Threshold` token with maximum value @@ -115,4 +124,3 @@ impl Threshold { self.value } } -