-
Notifications
You must be signed in to change notification settings - Fork 5
Use Corouitne/Task id #431
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
Changes from all commits
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 |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| use crate::catch; | ||
| use crate::common::ordered_work_steal::Ordered; | ||
| use std::ffi::c_longlong; | ||
| use std::hash::{DefaultHasher, Hash, Hasher}; | ||
|
|
||
| /// 做C兼容时会用到 | ||
| pub type UserTaskFunc = extern "C" fn(usize) -> usize; | ||
|
|
@@ -10,6 +11,7 @@ pub type UserTaskFunc = extern "C" fn(usize) -> usize; | |
| #[derive(educe::Educe)] | ||
| #[educe(Debug)] | ||
| pub struct Task<'t> { | ||
| id: u64, | ||
| name: String, | ||
| #[educe(Debug(ignore))] | ||
| func: Box<dyn FnOnce(Option<usize>) -> Option<usize> + 't>, | ||
|
|
@@ -25,7 +27,11 @@ impl<'t> Task<'t> { | |
| param: Option<usize>, | ||
| priority: Option<c_longlong>, | ||
| ) -> Self { | ||
| let mut hasher = DefaultHasher::new(); | ||
| name.hash(&mut hasher); | ||
| let id = hasher.finish(); | ||
| Task { | ||
| id, | ||
| name, | ||
|
Comment on lines
+30
to
35
|
||
| func: Box::new(func), | ||
| param, | ||
|
|
@@ -35,10 +41,16 @@ impl<'t> Task<'t> { | |
|
|
||
| /// get the task name. | ||
| #[must_use] | ||
| pub fn get_name(&self) -> &str { | ||
| pub fn name(&self) -> &str { | ||
| &self.name | ||
| } | ||
|
|
||
| /// get the task id. | ||
| #[must_use] | ||
| pub fn id(&self) -> u64 { | ||
| self.id | ||
| } | ||
|
|
||
| /// execute the task | ||
| /// | ||
| /// # Errors | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,7 @@ use std::cell::{Cell, RefCell, UnsafeCell}; | |
| use std::collections::VecDeque; | ||
| use std::ffi::c_longlong; | ||
| use std::fmt::Debug; | ||
| use std::hash::{DefaultHasher, Hash, Hasher}; | ||
| use std::io::Error; | ||
|
|
||
| cfg_if::cfg_if! { | ||
|
|
@@ -25,6 +26,7 @@ cfg_if::cfg_if! { | |
| /// Use `corosensei` as the low-level coroutine. | ||
| #[repr(C)] | ||
| pub struct Coroutine<'c, Param, Yield, Return> { | ||
| pub(crate) id: u64, | ||
| pub(crate) name: String, | ||
| inner: corosensei::Coroutine<Param, Yield, Result<Return, &'static str>, DefaultStack>, | ||
| pub(crate) state: Cell<CoroutineState<Yield, Return>>, | ||
|
|
@@ -427,8 +429,12 @@ where | |
| co_name | ||
| ) | ||
| }); | ||
| let mut hasher = DefaultHasher::new(); | ||
| name.hash(&mut hasher); | ||
| let id = hasher.finish(); | ||
| #[allow(unused_mut)] | ||
| let mut co = Coroutine { | ||
| id, | ||
| name, | ||
|
Comment on lines
+432
to
438
|
||
| inner, | ||
| stack_infos, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.