Skip to content

Commit

Permalink
refactor(task): stop using the deprecated method wrapping_offset_from
Browse files Browse the repository at this point in the history
`wrapping_offset_from` was deprecated by
<rust-lang/rust#73580>.
  • Loading branch information
yvt committed Jun 25, 2020
1 parent 9cc6484 commit eb752db
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/constance/src/kernel/task.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! Tasks
use core::{cell::UnsafeCell, fmt, hash, marker::PhantomData, sync::atomic::Ordering};
use core::{cell::UnsafeCell, fmt, hash, marker::PhantomData, mem, sync::atomic::Ordering};
use num_traits::ToPrimitive;

use super::{
Expand Down Expand Up @@ -131,8 +131,9 @@ impl<System: Kernel> Task<System> {
};

// Calculate an `Id` from the task CB pointer
let offset =
(task_cb as *const TaskCb<_>).wrapping_offset_from(System::task_cb_pool().as_ptr());
let offset_bytes =
task_cb as *const TaskCb<_> as usize - System::task_cb_pool().as_ptr() as usize;
let offset = offset_bytes / mem::size_of::<TaskCb<System>>();

// Safety: Constructing a `Task` for a current task is allowed
let task = unsafe { Self::from_id(Id::new(offset as usize + 1).unwrap()) };
Expand Down

0 comments on commit eb752db

Please sign in to comment.