diff --git a/src/emu/proc.c b/src/emu/proc.c index 3d0f05a..b8a3696 100644 --- a/src/emu/proc.c +++ b/src/emu/proc.c @@ -155,6 +155,8 @@ proc_add_thread(struct proc *proc, struct thread *thread) HASH_ADD_INT(proc->threads, tid, thread); proc->nthreads++; + thread_set_proc(thread, proc); + return 0; } diff --git a/src/emu/system.c b/src/emu/system.c index 4891993..53c4b28 100644 --- a/src/emu/system.c +++ b/src/emu/system.c @@ -28,7 +28,7 @@ create_thread(struct proc *proc, const char *relpath) return NULL; } - if (thread_init_begin(thread, proc, relpath) != 0) { + if (thread_init_begin(thread, relpath) != 0) { err("cannot init thread"); return NULL; } diff --git a/src/emu/thread.c b/src/emu/thread.c index b9491b0..3e64e66 100644 --- a/src/emu/thread.c +++ b/src/emu/thread.c @@ -61,13 +61,12 @@ thread_relpath_get_tid(const char *relpath, int *tid) } int -thread_init_begin(struct thread *thread, struct proc *proc, const char *relpath) +thread_init_begin(struct thread *thread, const char *relpath) { memset(thread, 0, sizeof(struct thread)); thread->state = TH_ST_UNKNOWN; thread->gindex = -1; - thread->proc = proc; if (snprintf(thread->id, PATH_MAX, "%s", relpath) >= PATH_MAX) { err("relpath too long"); @@ -88,6 +87,12 @@ thread_set_gindex(struct thread *th, int64_t gindex) th->gindex = gindex; } +void +thread_set_proc(struct thread *th, struct proc *proc) +{ + th->proc = proc; +} + int thread_init_end(struct thread *th) { diff --git a/src/emu/thread.h b/src/emu/thread.h index 0eae38e..f3dfae0 100644 --- a/src/emu/thread.h +++ b/src/emu/thread.h @@ -73,7 +73,7 @@ struct thread { }; int thread_relpath_get_tid(const char *relpath, int *tid); -int thread_init_begin(struct thread *thread, struct proc *proc, const char *relpath); +int thread_init_begin(struct thread *thread, const char *relpath); int thread_init_end(struct thread *thread); int thread_set_state(struct thread *th, enum thread_state state); int thread_set_cpu(struct thread *th, struct cpu *cpu); @@ -81,6 +81,7 @@ int thread_unset_cpu(struct thread *th); int thread_migrate_cpu(struct thread *th, struct cpu *cpu); int thread_get_tid(struct thread *thread); void thread_set_gindex(struct thread *th, int64_t gindex); +void thread_set_proc(struct thread *th, struct proc *proc); int thread_connect(struct thread *th, struct bay *bay, struct recorder *rec); int thread_select_active(struct mux *mux, struct value value, struct mux_input **input); diff --git a/test/unit/cpu.c b/test/unit/cpu.c index f1e0979..23601e8 100644 --- a/test/unit/cpu.c +++ b/test/unit/cpu.c @@ -24,12 +24,9 @@ test_oversubscription(void) * affinity rules */ proc.metadata_loaded = 1; - if (proc_init_end(&proc) != 0) - die("proc_init_end failed"); - struct thread th0, th1; - if (thread_init_begin(&th0, &proc, "loom.0/proc.0/thread.0.obs") != 0) + if (thread_init_begin(&th0, "loom.0/proc.0/thread.0.obs") != 0) die("thread_init_begin failed"); thread_set_gindex(&th0, 0); @@ -37,7 +34,7 @@ test_oversubscription(void) if (thread_init_end(&th0) != 0) die("thread_init_end failed"); - if (thread_init_begin(&th1, &proc, "loom.1/proc.1/thread.1.obs") != 0) + if (thread_init_begin(&th1, "loom.1/proc.1/thread.1.obs") != 0) die("thread_init_begin failed"); thread_set_gindex(&th1, 1); @@ -45,6 +42,15 @@ test_oversubscription(void) if (thread_init_end(&th1) != 0) die("thread_init_end failed"); + if (proc_add_thread(&proc, &th0) != 0) + die("proc_add_thread failed"); + + if (proc_add_thread(&proc, &th1) != 0) + die("proc_add_thread failed"); + + if (proc_init_end(&proc) != 0) + die("proc_init_end failed"); + if (thread_set_cpu(&th0, &cpu) != 0) die("thread_set_cpu failed");