New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add OwnedTasks #3909
Add OwnedTasks #3909
Changes from 1 commit
7371a05
7da217d
a5c056d
17c5e94
97b8af1
6dd8e1f
4bc20d0
1ab64db
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
use crate::loom::sync::Mutex; | ||
use crate::runtime::task::Task; | ||
use crate::util::linked_list::{Link, LinkedList}; | ||
|
||
pub(crate) struct OwnedTasks<S: 'static> { | ||
list: Mutex<LinkedList<Task<S>, <Task<S> as Link>::Target>>, | ||
} | ||
|
||
impl<S: 'static> OwnedTasks<S> { | ||
pub(crate) fn new() -> Self { | ||
Self { | ||
list: Mutex::new(LinkedList::new()), | ||
} | ||
} | ||
|
||
pub(crate) fn push_front(&self, task: Task<S>) { | ||
self.list.lock().push_front(task); | ||
} | ||
|
||
pub(crate) fn pop_back(&self) -> Option<Task<S>> { | ||
self.list.lock().pop_back() | ||
} | ||
|
||
/// The caller must ensure that if the provided task is stored in a | ||
/// linked list, then it is in this linked list. | ||
pub(crate) unsafe fn remove(&self, task: &Task<S>) -> Option<Task<S>> { | ||
self.list.lock().remove(task.header().into()) | ||
} | ||
Comment on lines
+24
to
+28
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We had discussed introducing a field in the task header to remember which There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, which would be solved if the only way to get a owned_tasks.insert(async { ... }) -> Task<_>; By doing this, the pointer to the OwnedTask in the task header is set on creation and never changed. This can be done in a follow-up API though, we can keep |
||
|
||
pub(crate) fn is_empty(&self) -> bool { | ||
self.list.lock().is_empty() | ||
} | ||
} |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
was the intention behind leaving this an enum just to keep the diff smaller? it seems like it could be changed to a
Schedule
struct, and just making the run queue aVecDeque<Schedule>
...