Added a task wakeup callback. Closes #599.
The callback happens when a task moves from the "blocked" state to the "running" state. The callback is also inherited by child tasks. There is currently only a native API. This code hasn't been heavily exercised yet.
This commit is contained in:
parent
bbdba21b1f
commit
bc5d6aefda
3 changed files with 22 additions and 2 deletions
|
@ -291,8 +291,10 @@ rust_scheduler::create_task(rust_task *spawner, const char *name) {
|
||||||
new (this->kernel) rust_task (this, &newborn_tasks, spawner, name);
|
new (this->kernel) rust_task (this, &newborn_tasks, spawner, name);
|
||||||
DLOG(this, task, "created task: " PTR ", spawner: %s, name: %s",
|
DLOG(this, task, "created task: " PTR ", spawner: %s, name: %s",
|
||||||
task, spawner ? spawner->name : "null", name);
|
task, spawner ? spawner->name : "null", name);
|
||||||
if(spawner)
|
if(spawner) {
|
||||||
task->pin(spawner->pinned_on);
|
task->pin(spawner->pinned_on);
|
||||||
|
task->on_wakeup(spawner->_on_wakeup);
|
||||||
|
}
|
||||||
newborn_tasks.append(task);
|
newborn_tasks.append(task);
|
||||||
return task;
|
return task;
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,7 +73,8 @@ rust_task::rust_task(rust_scheduler *sched, rust_task_list *state,
|
||||||
running_on(-1),
|
running_on(-1),
|
||||||
pinned_on(-1),
|
pinned_on(-1),
|
||||||
local_region(&sched->srv->local_region),
|
local_region(&sched->srv->local_region),
|
||||||
synchronized_region(&sched->srv->synchronized_region)
|
synchronized_region(&sched->srv->synchronized_region),
|
||||||
|
_on_wakeup(NULL)
|
||||||
{
|
{
|
||||||
LOGPTR(sched, "new task", (uintptr_t)this);
|
LOGPTR(sched, "new task", (uintptr_t)this);
|
||||||
DLOG(sched, task, "sizeof(task) = %d (0x%x)", sizeof *this, sizeof *this);
|
DLOG(sched, task, "sizeof(task) = %d (0x%x)", sizeof *this, sizeof *this);
|
||||||
|
@ -431,6 +432,10 @@ rust_task::wakeup(rust_cond *from) {
|
||||||
I(sched, cond == from);
|
I(sched, cond == from);
|
||||||
cond = NULL;
|
cond = NULL;
|
||||||
cond_name = "none";
|
cond_name = "none";
|
||||||
|
|
||||||
|
if(_on_wakeup) {
|
||||||
|
_on_wakeup->on_wakeup();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -541,6 +546,10 @@ void rust_task::unpin() {
|
||||||
pinned_on = -1;
|
pinned_on = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void rust_task::on_wakeup(rust_task::wakeup_callback *callback) {
|
||||||
|
_on_wakeup = callback;
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Local Variables:
|
// Local Variables:
|
||||||
// mode: C++
|
// mode: C++
|
||||||
|
|
|
@ -83,6 +83,13 @@ rust_task : public maybe_proxy<rust_task>,
|
||||||
memory_region local_region;
|
memory_region local_region;
|
||||||
memory_region synchronized_region;
|
memory_region synchronized_region;
|
||||||
|
|
||||||
|
class wakeup_callback {
|
||||||
|
public:
|
||||||
|
virtual void on_wakeup() = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
wakeup_callback *_on_wakeup;
|
||||||
|
|
||||||
// Only a pointer to 'name' is kept, so it must live as long as this task.
|
// Only a pointer to 'name' is kept, so it must live as long as this task.
|
||||||
rust_task(rust_scheduler *sched,
|
rust_task(rust_scheduler *sched,
|
||||||
rust_task_list *state,
|
rust_task_list *state,
|
||||||
|
@ -156,6 +163,8 @@ rust_task : public maybe_proxy<rust_task>,
|
||||||
void pin();
|
void pin();
|
||||||
void pin(int id);
|
void pin(int id);
|
||||||
void unpin();
|
void unpin();
|
||||||
|
|
||||||
|
void on_wakeup(wakeup_callback *callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue