X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=threads.cc;h=8af66bde53a6946a153d2009c04e554495d4b8eb;hb=ed4c0c4095856c1cfadf14ec868acd487ed88600;hp=8ee3bf975e732d7c943e512005c2dfd9eb218118;hpb=d47c480e46b9a7318dfaa50398a83db04171f83e;p=c11tester.git diff --git a/threads.cc b/threads.cc index 8ee3bf97..8af66bde 100644 --- a/threads.cc +++ b/threads.cc @@ -59,21 +59,14 @@ Thread * thread_current(void) return model->get_current_thread(); } -#ifdef TLS void modelexit() { model->switch_to_master(new ModelAction(THREAD_FINISH, std::memory_order_seq_cst, thread_current())); } -#endif -void main_thread_startup() { -#ifdef TLS +void initMainThread() { atexit(modelexit); Thread * curr_thread = thread_current(); - - /* Add dummy "start" action, just to create a first clock vector */ model->switch_to_master(new ModelAction(THREAD_START, std::memory_order_seq_cst, curr_thread)); -#endif - thread_startup(); } /** @@ -249,7 +242,7 @@ void setup_context() { Thread * curr_thread = thread_current(); /* Add dummy "start" action, just to create a first clock vector */ - model->switch_to_master(new ModelAction(THREAD_START, std::memory_order_seq_cst, curr_thread)); + model->switch_thread(new ModelAction(THREAD_START, std::memory_order_seq_cst, curr_thread)); real_init_all(); @@ -293,10 +286,7 @@ int Thread::create_context() context.uc_stack.ss_flags = 0; context.uc_link = model->get_system_context(); #ifdef TLS - if (model != NULL) - makecontext(&context, setup_context, 0); - else - makecontext(&context, main_thread_startup, 0); + makecontext(&context, setup_context, 0); #else makecontext(&context, thread_startup, 0); #endif @@ -340,6 +330,16 @@ int Thread::swap(ucontext_t *ctxt, Thread *t) return model_swapcontext(ctxt, &t->context); } +int Thread::swap(Thread *t, Thread *t2) +{ + t->set_state(THREAD_READY); + t2->set_state(THREAD_RUNNING); +#ifdef TLS + if (t2->tls != NULL) + set_tls_addr((uintptr_t)t2->tls); +#endif + return model_swapcontext(&t->context, &t2->context); +} /** Terminate a thread and free its stack. */ void Thread::complete()