mirror of
https://github.com/embassy-rs/embassy.git
synced 2025-10-03 07:04:46 +00:00
Do not access task header
This commit is contained in:
parent
12f58fbcfd
commit
dc18ee29a0
@ -82,6 +82,12 @@ impl TaskRef {
|
|||||||
self.header().executor.get().map(|e| Executor::wrap(e))
|
self.header().executor.get().map(|e| Executor::wrap(e))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns a reference to the timer queue item.
|
||||||
|
#[cfg(feature = "integrated-timers")]
|
||||||
|
pub fn timer_queue_item(&self) -> &'static timer_queue::TimerQueueItem {
|
||||||
|
&self.header().timer_queue_item
|
||||||
|
}
|
||||||
|
|
||||||
/// The returned pointer is valid for the entire TaskStorage.
|
/// The returned pointer is valid for the entire TaskStorage.
|
||||||
pub(crate) fn as_ptr(self) -> *const TaskHeader {
|
pub(crate) fn as_ptr(self) -> *const TaskHeader {
|
||||||
self.ptr.as_ptr()
|
self.ptr.as_ptr()
|
||||||
|
@ -4,13 +4,14 @@ use core::cmp::min;
|
|||||||
use super::util::SyncUnsafeCell;
|
use super::util::SyncUnsafeCell;
|
||||||
use super::TaskRef;
|
use super::TaskRef;
|
||||||
|
|
||||||
pub(crate) struct TimerQueueItem {
|
/// An item in the timer queue.
|
||||||
|
pub struct TimerQueueItem {
|
||||||
next: SyncUnsafeCell<Option<TaskRef>>,
|
next: SyncUnsafeCell<Option<TaskRef>>,
|
||||||
expires_at: SyncUnsafeCell<u64>,
|
expires_at: SyncUnsafeCell<u64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TimerQueueItem {
|
impl TimerQueueItem {
|
||||||
pub const fn new() -> Self {
|
pub(crate) const fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
next: SyncUnsafeCell::new(None),
|
next: SyncUnsafeCell::new(None),
|
||||||
expires_at: SyncUnsafeCell::new(0),
|
expires_at: SyncUnsafeCell::new(0),
|
||||||
@ -37,8 +38,7 @@ impl TimerQueue {
|
|||||||
/// a new alarm for that time.
|
/// a new alarm for that time.
|
||||||
pub fn schedule_wake(&mut self, at: u64, p: TaskRef) -> bool {
|
pub fn schedule_wake(&mut self, at: u64, p: TaskRef) -> bool {
|
||||||
unsafe {
|
unsafe {
|
||||||
let task = p.header();
|
let item = p.timer_queue_item();
|
||||||
let item = &task.timer_queue_item;
|
|
||||||
if item.next.get().is_none() {
|
if item.next.get().is_none() {
|
||||||
// If not in the queue, add it and update.
|
// If not in the queue, add it and update.
|
||||||
let prev = self.head.replace(Some(p));
|
let prev = self.head.replace(Some(p));
|
||||||
@ -63,8 +63,7 @@ impl TimerQueue {
|
|||||||
let mut next_expiration = u64::MAX;
|
let mut next_expiration = u64::MAX;
|
||||||
|
|
||||||
self.retain(|p| {
|
self.retain(|p| {
|
||||||
let task = p.header();
|
let item = p.timer_queue_item();
|
||||||
let item = &task.timer_queue_item;
|
|
||||||
let expires = unsafe { item.expires_at.get() };
|
let expires = unsafe { item.expires_at.get() };
|
||||||
|
|
||||||
if expires <= now {
|
if expires <= now {
|
||||||
@ -85,8 +84,7 @@ impl TimerQueue {
|
|||||||
unsafe {
|
unsafe {
|
||||||
let mut prev = &self.head;
|
let mut prev = &self.head;
|
||||||
while let Some(p) = prev.get() {
|
while let Some(p) = prev.get() {
|
||||||
let task = p.header();
|
let item = p.timer_queue_item();
|
||||||
let item = &task.timer_queue_item;
|
|
||||||
if f(p) {
|
if f(p) {
|
||||||
// Skip to next
|
// Skip to next
|
||||||
prev = &item.next;
|
prev = &item.next;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user