enum pause_reason single_step(struct thread *thread) { assert(!InInterpreter); assert(thread->status == status_Running); assert(thread->suspend_count == 0); check_fds(false); thread_set_current(thread); InInterpreter = true; PauseReason = pause_NoReason; set_interrupt_handler(set_pause_interrupted); if (_setjmp(Catcher) == 0) { #if SLOW_FUNCTION_POINTERS if (thread->advance) thread->advance(thread); else interpret_next_byte(thread); #else thread->advance(thread); #endif } InInterpreter = false; clear_interrupt_handler(); if (TimeToGC) collect_garbage(false); return PauseReason; }
ret_t threading_setup(uint32_t init_thread_stack_base_address, uint32_t init_thread_stack_size) { struct thread *myself; TAILQ_INIT(&kernel_threads); /* Allocate a new thread structure for the current running thread */ myself = (struct thread *)malloc(sizeof(struct thread)); if (!myself) return -KERNEL_NO_MEMORY; /* Initialize the thread attributes */ strzcpy(myself->name, "[kinit]", THREAD_MAX_NAMELEN); myself->state = THREAD_CREATED; myself->kernel_stack_base_address = init_thread_stack_base_address; myself->kernel_stack_size = init_thread_stack_size; /* Add the thread in the global list */ TAILQ_INSERT_TAIL(&kernel_threads, myself, next); /* Ok, now pretend that the running thread is ourselves */ myself->state = THREAD_READY; thread_set_current(myself); return KERNEL_OK; }
void * thread_run0_main(void *p) { struct thread *t; t = (struct thread *)p; if (thread_set_current(t) != 0) mvm_halt(); t->state = runnable_state; if (debug != 0) mdb_hook(startup_hook); main_block_return_value = 0; if (invoke_method(t, "mainBlock", main_block_address, main_block_end, 0, main_block_max_locals, 0) != 0) { mvm_halt(); } #ifdef DMP if (t->dmp != NULL) thread_dmp_thread_destruction(t->dmp); #endif t->state = terminated_state; /* run method has terminated, thread instance can now be collected */ heap_include_ref(heap, t->ref); heap_remove_thread_ref(heap, t->ref); pthread_exit(0); }
void * thread_run0(void *p) { struct thread *t; t = (struct thread *)p; if (thread_set_current(t) != 0) mvm_halt(); #ifdef DMP if (t->dmp != NULL) thread_dmp_thread_start(t->dmp); #endif t->state = runnable_state; if (invoke_virtual_method_by_name(t, t->ref, t->pc, "run", 0) != 0) mvm_halt(); #ifdef DMP if (t->dmp != NULL) thread_dmp_thread_destruction(t->dmp); #endif t->state = terminated_state; /* run method has terminated, thread instance can now be collected */ heap_include_ref(heap, t->ref); heap_remove_thread_ref(heap, t->ref); pthread_exit(0); }
static struct schedee *thread_process(struct schedee *prev, struct schedee *next) { struct thread *next_t, *prev_t; next_t = mcast_out(next, struct thread, schedee); prev_t = mcast_out(prev, struct thread, schedee); thread_set_current(next_t); /* Threads context switch */ if (prev != next) { thread_context_switch(prev_t, next_t); } ipl_enable(); if (!prev_t->siglock) { thread_signal_handle(); } return &thread_self()->schedee; }