diff --git a/co_routine.cpp b/co_routine.cpp index a0a0bcd..352ae7e 100644 --- a/co_routine.cpp +++ b/co_routine.cpp @@ -535,6 +535,17 @@ void co_free( stCoRoutine_t *co ) free(co->stack_mem->stack_buffer); free(co->stack_mem); } + //walkerdu fix at 2018-01-20 + //存在内存泄漏 + else + { + if(co->save_buffer) + free(co->save_buffer); + + if(co->stack_mem->occupy_co == co) + co->stack_mem->occupy_co = NULL; + } + free( co ); } void co_release( stCoRoutine_t *co ) @@ -558,6 +569,31 @@ void co_resume( stCoRoutine_t *co ) } + + +// walkerdu 2018-01-14 +// 用于reset超时无法重复使用的协程 +void co_reset(stCoRoutine_t * co) +{ + if(!co->cStart || co->cIsMain) + return; + + co->cStart = 0; + co->cEnd = 0; + + // 如果当前协程有共享栈被切出的buff,要进行释放 + if(co->save_buffer) + { + free(co->save_buffer); + co->save_buffer = NULL; + co->save_size = 0; + } + + // 如果共享栈被当前协程占用,要释放占用标志,否则被切换,会执行save_stack_buffer() + if(co->stack_mem->occupy_co == co) + co->stack_mem->occupy_co = NULL; +} + void co_yield_env( stCoRoutineEnv_t *env ) { diff --git a/co_routine.h b/co_routine.h index b849713..d6f4789 100644 --- a/co_routine.h +++ b/co_routine.h @@ -50,6 +50,7 @@ void co_resume( stCoRoutine_t *co ); void co_yield( stCoRoutine_t *co ); void co_yield_ct(); //ct = current thread void co_release( stCoRoutine_t *co ); +void co_reset(stCoRoutine_t * co); stCoRoutine_t *co_self();