void co_update(co_thread_t t) { cothread_ctx* tctx = (cothread_ctx*)t; while(coroutine* c=(coroutine*)bd_pop_back(&tctx->co_ready_list)) { c->status = co_stat_run; swap_context(tctx, tctx->co_main, c); } while(coroutine* c=(coroutine*)bd_pop_back(&tctx->co_dead_list)) { if(c->stk_size == tctx->co_stack_size) { if(tctx->co_cache_list.count < (tctx->high_watermark)) { c->status = co_stat_null; bd_push_front(&tctx->co_cache_list, &c->node); continue; } } cleanup_coroutine(c); free_coroutine(c); } }
void co_thread_cleanup(co_thread_t t) { if(t == NULL) return; cothread_ctx* tctx = (cothread_ctx*)t; free_coroutine(tctx->co_main); tctx->co_main = NULL; tctx->co_curr = NULL; while(coroutine* c=(coroutine*)bd_pop_back(&tctx->co_cache_list)) { cleanup_coroutine(c); free_coroutine(c); } while(coroutine* c=(coroutine*)bd_pop_back(&tctx->co_dead_list)) { cleanup_coroutine(c); free_coroutine(c); } //while(coroutine* c=(coroutine*)bd_pop_back(&tctx->co_wait_list)) //{ // cleanup_coroutine(c); // free_coroutine(c); //} while(coroutine* c=(coroutine*)bd_pop_back(&tctx->co_ready_list)) { cleanup_coroutine(c); free_coroutine(c); } free(tctx); }
coroutine* create_coroutine(cothread_ctx* tctx, size_t ssize) { coroutine* c = malloc_coroutine(); if(c == NULL) { return NULL; } if(setup_coroutine(tctx, c, ssize) == -1) { free_coroutine(c); return NULL; } return c; }
int delay_del_coroutine(void *arg) { coroutine_t * co = (coroutine_t *)(arg); free_coroutine(co); return 0; }