hawkw/mycelium

maitake: `Schedule::current_task` method

hawkw opened this issue · 0 comments

hawkw commented

It would be nice to have a function for getting the current task. This can be used by leaf futures if they want to self-wake, access information about what task they're being polled from, such as for debugging (see #265 and #267) , or forcibly cancel the current task (see #264).

maitake itself can't implement an "ambiently available" task::current() function, because it doesn't know about "locality"1. But, we can add a method to the Scheduler types for accessing the task that scheduler is currently polling. Then, the OS can use this to implement a task::current() by finding the current core's scheduler (or picking the global one if single-core).

I imagine this would have a signature like

pub fn current_task(&self) -> Option<TaskRef>

We would probably have to store the task ptr in an AtomicPointer in the scheduler, and load that and that into a TaskRef if someone wants it.

Footnotes

  1. Are we single-core, and there's a single global scheduler? Or are we multi-core, and each core has its own scheduler? And if so, how do I access the scheduler for the current core? Those are all OS-level concerns that maitake can't handle.