void native_thread_invoke(u08_t mref) { heap_id_t method_h,thread_h; u16_t method_id,thread_id; if(mref == NATIVE_METHOD_THREAD_RUNNABLE) { // nvm_method_hdr_t mhdr, *mhdr_ptr; method_h = stack_pop(); thread_h = stack_pop(); method_id = ((nvm_ref_t*)heap_get_addr(method_h))[0]; thread_id = ((nvm_ref_t*)heap_get_addr(thread_h))[0]; Task_init(&SubThread[thread_id],vm_run, (void*)(method_id&0xFF), CONFIG_MAX_PRIORITY - 1, SubThread_stack[thread_id], sizeof(SubThread_stack[thread_id])); // mhdr_ptr = nvmfile_get_method_hdr(method_id&0xFF); // load new method header into ram // nvmfile_read(&mhdr, mhdr_ptr, sizeof(nvm_method_hdr_t)); // heap_steal(sizeof(nvm_stack_t) * (mhdr.max_locals + mhdr.max_stack + mhdr.args)); // Task_setjsp(mhdr. //stack_push(NVM_TYPE_HEAP | thread_h); } else if(mref == NATIVE_METHOD_THREAD_START) { thread_h = stack_pop(); thread_id = ((nvm_ref_t*)heap_get_addr(thread_h))[0]; SubThread[thread_id].j_sp = (unsigned int*)&heap[heap_base]; SubThread[thread_id].j_stack = (unsigned int*)&heap[heap_base]; Task_start(&SubThread[thread_id]); //Task_yield(); } }
/* * taskid := start(main_func) */ int clip_START(ClipMachine * mp) { Task *tp; char *name, *tname="block"; start_data *sp; int argc = mp->argc-1; int i; ClipVar *stack; static int first = 1; int type; type = _clip_parinfo(mp, 1); if (type != CHARACTER_t && type != CCODE_t && type != PCODE_t) return EG_ARG; name = _clip_parc(mp, 1); stack = malloc(sizeof(ClipVar) * (argc + 1)); memset(stack, 0, sizeof(ClipVar) * (argc + 1)); for (i = 0; i < argc; ++i) _clip_clone(mp, stack + i, ARGPTR(mp, i + 2)); sp = calloc(sizeof(start_data), 1); sp->stack = stack; sp->argc = argc; if (name) tname = sp->name = strdup(name); else _clip_clone(mp, &sp->block, _clip_spar(mp, 1)); sp->mp = mp; tp = Task_new(tname, 4096*32, sp, task_run, task_destroy); if (tp == NULL) _clip_retnl(mp,-1); _clip_retnl(mp, Task_get_id(tp)); Task_start(tp); if (first) { Task_start_sheduler(); first = 0; } Task_yield(); return 0; }
int main(int argc, char **argv) { int i; Task *tp; for (i = 0; i < 3; i++) { tp = Task_new("task_test", 8192, 0, run, 0); Task_start(tp); } Task_start_sheduler(); for (i = 0; i < 15; i++) { printf("main task: cycle %d\n", i); Task_sleep(50); } /*Task_killAll(); */ return 0; }