aboutsummaryrefslogtreecommitdiff
path: root/src/lib.rs
diff options
context:
space:
mode:
authorJorge Aparicio <japaricious@gmail.com>2017-03-11 18:02:11 -0500
committerJorge Aparicio <japaricious@gmail.com>2017-03-11 18:02:11 -0500
commit2d6af9b5df892eac749f1703738356344c35452d (patch)
treed21ff5b18a07b3d45163d69d708e889aba36d294 /src/lib.rs
parentfd858a199476e6c09e6195856b742e43f2f70254 (diff)
make `logical` non-`const`, check input using assertions
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs12
1 files changed, 4 insertions, 8 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 353d630..6fcbded 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -249,15 +249,11 @@ unsafe impl<T, Ceiling> Sync for Resource<T, Ceiling> {}
/// priorities encode the actual priority in the highest bits of a byte so
/// priorities like `1` and `2` aren't actually different)
///
-/// NOTE `logical` must be in the range `[1, 15]` (inclusive)
-pub const fn logical(priority: u8) -> u8 {
- // NOTE elements 1 and 2 of the tuple are a poor man's const context range
- // checker
- (((1 << PRIORITY_BITS) - priority) << (8 - PRIORITY_BITS),
- priority - 1,
- priority + 240)
- .0
+/// NOTE Input `priority` must be in the range `[1, 16]` (inclusive)
+pub fn logical(priority: u8) -> u8 {
+ assert!(priority >= 1 && priority <= 16);
+ ((1 << PRIORITY_BITS) - priority) << (8 - PRIORITY_BITS)
}
/// Fake ceiling, indicates that the resource is shared by cooperative tasks