rt: Move transition from rust_task to rust_task_thread
This commit is contained in:
parent
237652299e
commit
2465a63a69
4 changed files with 42 additions and 22 deletions
|
@ -401,26 +401,16 @@ rust_task::free(void *p)
|
||||||
void
|
void
|
||||||
rust_task::transition(rust_task_list *src, rust_task_list *dst,
|
rust_task::transition(rust_task_list *src, rust_task_list *dst,
|
||||||
rust_cond *cond, const char* cond_name) {
|
rust_cond *cond, const char* cond_name) {
|
||||||
bool unlock = false;
|
thread->transition(this, src, dst, cond, cond_name);
|
||||||
if(!thread->lock.lock_held_by_current_thread()) {
|
}
|
||||||
unlock = true;
|
|
||||||
thread->lock.lock();
|
void
|
||||||
}
|
rust_task::set_state(rust_task_list *state,
|
||||||
DLOG(thread, task,
|
rust_cond *cond, const char* cond_name) {
|
||||||
"task %s " PTR " state change '%s' -> '%s' while in '%s'",
|
scoped_lock with(state_lock);
|
||||||
name, (uintptr_t)this, src->name, dst->name, state->name);
|
this->state = state;
|
||||||
I(thread, state == src);
|
this->cond = cond;
|
||||||
src->remove(this);
|
this->cond_name = cond_name;
|
||||||
dst->append(this);
|
|
||||||
{
|
|
||||||
scoped_lock with(state_lock);
|
|
||||||
state = dst;
|
|
||||||
this->cond = cond;
|
|
||||||
this->cond_name = cond_name;
|
|
||||||
}
|
|
||||||
thread->lock.signal();
|
|
||||||
if(unlock)
|
|
||||||
thread->lock.unlock();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -137,6 +137,9 @@ private:
|
||||||
|
|
||||||
void return_c_stack();
|
void return_c_stack();
|
||||||
|
|
||||||
|
void transition(rust_task_list *src, rust_task_list *dst,
|
||||||
|
rust_cond *cond, const char* cond_name);
|
||||||
|
|
||||||
friend void task_start_wrapper(spawn_args *a);
|
friend void task_start_wrapper(spawn_args *a);
|
||||||
friend void cleanup_task(cleanup_args *a);
|
friend void cleanup_task(cleanup_args *a);
|
||||||
friend void reset_stack_limit_on_c_stack(reset_args *a);
|
friend void reset_stack_limit_on_c_stack(reset_args *a);
|
||||||
|
@ -163,8 +166,8 @@ public:
|
||||||
void *realloc(void *data, size_t sz);
|
void *realloc(void *data, size_t sz);
|
||||||
void free(void *p);
|
void free(void *p);
|
||||||
|
|
||||||
void transition(rust_task_list *src, rust_task_list *dst,
|
void set_state(rust_task_list *state,
|
||||||
rust_cond *cond, const char* cond_name);
|
rust_cond *cond, const char* cond_name);
|
||||||
|
|
||||||
void block(rust_cond *on, const char* name);
|
void block(rust_cond *on, const char* name);
|
||||||
void wakeup(rust_cond *from);
|
void wakeup(rust_cond *from);
|
||||||
|
|
|
@ -319,6 +319,29 @@ rust_task_thread::create_task(rust_task *spawner, const char *name,
|
||||||
return task->id;
|
return task->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
rust_task_thread::transition(rust_task *task,
|
||||||
|
rust_task_list *src, rust_task_list *dst,
|
||||||
|
rust_cond *cond, const char* cond_name) {
|
||||||
|
bool unlock = false;
|
||||||
|
if(!lock.lock_held_by_current_thread()) {
|
||||||
|
unlock = true;
|
||||||
|
lock.lock();
|
||||||
|
}
|
||||||
|
DLOG(this, task,
|
||||||
|
"task %s " PTR " state change '%s' -> '%s' while in '%s'",
|
||||||
|
name, (uintptr_t)this, src->name, dst->name,
|
||||||
|
task->get_state()->name);
|
||||||
|
I(this, task->get_state() == src);
|
||||||
|
src->remove(task);
|
||||||
|
dst->append(task);
|
||||||
|
task->set_state(dst, cond, cond_name);
|
||||||
|
|
||||||
|
lock.signal();
|
||||||
|
if(unlock)
|
||||||
|
lock.unlock();
|
||||||
|
}
|
||||||
|
|
||||||
void rust_task_thread::run() {
|
void rust_task_thread::run() {
|
||||||
this->start_main_loop();
|
this->start_main_loop();
|
||||||
sched->release_task_thread();
|
sched->release_task_thread();
|
||||||
|
|
|
@ -123,6 +123,10 @@ public:
|
||||||
rust_task_id create_task(rust_task *spawner, const char *name,
|
rust_task_id create_task(rust_task *spawner, const char *name,
|
||||||
size_t init_stack_sz);
|
size_t init_stack_sz);
|
||||||
|
|
||||||
|
void transition(rust_task *task,
|
||||||
|
rust_task_list *src, rust_task_list *dst,
|
||||||
|
rust_cond *cond, const char* cond_name);
|
||||||
|
|
||||||
virtual void run();
|
virtual void run();
|
||||||
|
|
||||||
void init_tls();
|
void init_tls();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue