int main(void) { if( log_init(LOG_INFO, "sched_switch_t.log") < 0 ) { printf("init log error.\n"); return 0; } if( env_init() != 0) { return 0; } coro_spawn(g_mastersched, &func, NULL, 8192); coro_spawn(g_mastersched, &func, NULL, 8192); log_warn("Init scheduler success, start..."); int rs = env_run(); log_warn("Scheduler stop, status:%d", rs); return 0; }
// TODO: refactor not to take <me> argument Worker * worker_spawn(Worker * me, Scheduler * sched, thread_func f, void * arg) { CHECK( sched->get_current_thread() == me ) << "parent arg differs from current thread"; // allocate the Worker and stack Worker * thr = new Worker( ); thr->sched = sched; sched->assignTid( thr ); coro_spawn(me, thr, tramp, FLAGS_stack_size); // Pass control to the trampoline a few times quickly to set up // the call of <f>. Could also create a struct with all this data? coro_invoke(me, thr, (void *)me); coro_invoke(me, thr, thr); coro_invoke(me, thr, (void *)f); coro_invoke(me, thr, (void *)arg); return thr; }