remove the borrow_mut method from resources

it can be used to break references rules within nested locks

``` rust
static R1: Resource<bool, C1> = unsafe { Resource::new(false) };
static R2: Resource<bool, C2> = unsafe { Resource::new(false) };
static R3: Resource<bool, C3> = unsafe { Resource::new(false) };

// Priority = 1
extern "C" fn j1(task: interrupt::Exti0Irq) {
    R1.lock(&task, |r1, c1| {
        R2.lock(&task, |r2, c2| {
            R3.lock(&task, |r3, mut c3| {
                // BAD &- and &mut - that point to the same data
                let r1_ref: &bool = R1.borrow(&c2);
                let r1_ref_mut: &mut bool = R1.borrow_mut(&mut c3);
            });
        });
    });
}
```
This commit is contained in:
Jorge Aparicio 2017-04-07 16:38:39 -05:00
parent e631d8513a
commit 759ac160db

View file

@ -180,19 +180,6 @@ where
unsafe { &*self.peripheral.get() }
}
/// Mutably borrows the resource without locking
///
/// NOTE The system ceiling must be higher than this resource ceiling
pub fn borrow_mut<'l, SC>(
&'static self,
_system_ceiling: &'l mut SC,
) -> &'l mut P
where
SC: HigherThan<C>,
{
unsafe { &mut *self.peripheral.get() }
}
/// Returns an immutable reference to the inner data without locking
///
/// # Safety
@ -327,16 +314,6 @@ where
unsafe { &*self.data.get() }
}
/// Mutably borrows the resource without locking
///
/// NOTE The system ceiling must be higher than this resource ceiling
pub fn borrow_mut<'l, SC>(&'static self, _ctxt: &'l mut SC) -> &'l mut T
where
SC: HigherThan<C>,
{
unsafe { &mut *self.data.get() }
}
/// Returns an immutable reference to the inner data without locking
///
/// # Safety