Skip to content
Snippets Groups Projects
Commit f906aa20 authored by Per Lindgren's avatar Per Lindgren
Browse files

both claim_mut and claim_mut_new

parent fe366fea
No related branches found
No related tags found
No related merge requests found
......@@ -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
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment