void join() { if (!detached) return; #if defined(__APPLE__) || defined(__linux__) /* Release GIL and disassociate from thread state (which was originally associated with the main Python thread) */ py::gil_scoped_release thread_state(true); coro_transfer(&ctx_main, &ctx_thread); coro_stack_free(&stack); /* Destroy the thread state that was created in mainloop() */ { py::gil_scoped_acquire acquire; acquire.dec_ref(); } #endif thread.join(); detached = false; #if defined(__APPLE__) || defined(__linux__) /* Reacquire GIL and reassociate with thread state [via RAII destructor in 'thread_state'] */ #endif }
void uvc_schedule(){ uvc_ctx *ctx; queue_t *node; uvc_thread_env *env; env = uvc_get_env(); for (;;){ if (!queue_empty(&env->ready_queue) ){ node = queue_last(&env->ready_queue); queue_remove( node); ctx = queue_data(node, uvc_ctx, task_node); } else{ //只有当没有ready任务时才运行uvloop if (env->uv_task){ ctx = env->uv_task; } else{ printf("no task need run ,exit\n"); exit(0); } } if (ctx != NULL){ env->runing_task = ctx; ctx->status = UVC_STATUS_RUNING; //printf("task[%s] runing\n",ctx->name); uvc_resume(ctx); //printf("task[%s] stoping\n",ctx->name); } if (ctx->status == UVC_STATUS_DIE){ coro_stack_free(&ctx->stack); free(ctx); }else{ ctx->status = UVC_STATUS_PENDING; } } }