From d0ddc322e378e498743121121c8849260d2f1726 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Fri, 21 Apr 2017 21:38:39 -0500 Subject: rename `borrow` to `access` --- src/lib.rs | 73 +++++++++++++++++++++++++++++++------------------------------- 1 file changed, 37 insertions(+), 36 deletions(-) (limited to 'src/lib.rs') diff --git a/src/lib.rs b/src/lib.rs index a0c8a3b..74fcebe 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -420,20 +420,17 @@ impl Local { unsafe impl Sync for Local {} /// A resource with ceiling `C` -/// -/// Only tasks with priority equal to or smaller than `C` can access this -/// resource pub struct Resource { _ceiling: PhantomData, data: UnsafeCell, } -impl Resource> +impl Resource> where - CEILING: GreaterThanOrEqual, - CEILING: LessThanOrEqual, + RC: GreaterThanOrEqual, + RC: LessThanOrEqual, { - /// Creates a new resource with the specified `CEILING` + /// Creates a new resource pub const fn new(data: T) -> Self { Resource { _ceiling: PhantomData, @@ -442,21 +439,27 @@ where } } -impl Resource> { - /// Borrows the resource for the duration of a critical section +impl Resource> { + /// Grants data race free and deadlock free access to the resource data /// /// This operation is zero cost and doesn't impose any additional blocking. /// - /// **NOTE** Only tasks with a priority equal to or smaller than the - /// resource ceiling can access the resource. - pub fn borrow<'cs, PRIORITY, CCEILING>( + /// # Requirements + /// + /// To access the resource data these conditions must be met: + /// + /// - The resource ceiling must be greater than or equal to the task + /// priority + /// - The system ceiling must be greater than or equal to the resource + /// ceiling + pub fn access<'cs, TP, SC>( &'static self, - _priority: &P, - _current_ceiling: &'cs C, + _priority: &P, + _current_ceiling: &'cs C, ) -> Ref<'cs, T> where - CCEILING: GreaterThanOrEqual, - CEILING: GreaterThanOrEqual, + RC: GreaterThanOrEqual, + SC: GreaterThanOrEqual, { unsafe { Ref::new(&*self.data.get()) } } @@ -492,16 +495,16 @@ where } } -impl Peripheral> { - /// See [Resource.borrow](./struct.Resource.html#method.borrow) - pub fn borrow<'cs, PRIORITY, CCEILING>( +impl Peripheral> { + /// See [Resource.access](./struct.Resource.html#method.access) + pub fn access<'cs, TP, SC>( &'static self, - _priority: &P, - _current_ceiling: &'cs C, + _priority: &P, + _system_ceiling: &'cs C, ) -> Ref<'cs, Periph> where - CCEILING: GreaterThanOrEqual, - CEILING: GreaterThanOrEqual, + RC: GreaterThanOrEqual, + SC: GreaterThanOrEqual, { unsafe { Ref::new(&*self.peripheral.get()) } } @@ -569,19 +572,17 @@ pub struct C { _marker: PhantomData, } -impl C { - /// Raises the ceiling to match `resource`'s ceiling - pub fn raise(&self, _resource: &'static RES, f: F) -> R +impl C { + /// Raises the system ceiling to match the `resource` ceiling + pub fn raise(&self, _resource: &'static RES, f: F) -> R where - RES: ResourceLike, - HIGHER: Cmp, - HIGHER: Cmp, - HIGHER: Unsigned, - F: FnOnce(&C) -> R, + RES: ResourceLike, + RC: Cmp + Cmp + Unsigned, + F: FnOnce(&C) -> R, { unsafe { let old_basepri = basepri::read(); - basepri_max::write(logical2hw(HIGHER::to_u8())); + basepri_max::write(logical2hw(RC::to_u8())); barrier!(); let ret = f(&C { _marker: PhantomData }); barrier!(); @@ -614,12 +615,12 @@ pub unsafe trait ResourceLike { type Ceiling; } -unsafe impl ResourceLike for Peripheral> { - type Ceiling = CEILING; +unsafe impl ResourceLike for Peripheral> { + type Ceiling = RC; } -unsafe impl ResourceLike for Resource> { - type Ceiling = CEILING; +unsafe impl ResourceLike for Resource> { + type Ceiling = RC; } /// Type-level `>=` operator -- cgit v1.2.3