File tree Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -535,6 +535,14 @@ void co_free( stCoRoutine_t *co )
535
535
free (co->stack_mem ->stack_buffer );
536
536
free (co->stack_mem );
537
537
}
538
+ // walkerdu fix at 2018-01-20
539
+ // 存在内存泄漏
540
+ else
541
+ {
542
+ if (co->save_buffer )
543
+ free (co->save_buffer );
544
+ }
545
+
538
546
free ( co );
539
547
}
540
548
void co_release ( stCoRoutine_t *co )
@@ -558,6 +566,32 @@ void co_resume( stCoRoutine_t *co )
558
566
559
567
560
568
}
569
+
570
+
571
+ // walkerdu 2018-01-14
572
+ // 用于reset超时无法重复使用的协程
573
+ void co_reset (stCoRoutine_t * co)
574
+ {
575
+ if (!co->cStart || co->cIsMain )
576
+ return ;
577
+
578
+ co->cStart = 0 ;
579
+ co->cEnd = 0 ;
580
+
581
+ // 如果当前协程有共享栈被切出的buff,要进行释放
582
+ if (co->save_buffer )
583
+ {
584
+ free (co->save_buffer );
585
+ co->save_buffer = NULL ;
586
+ co->save_size = 0 ;
587
+ }
588
+
589
+ // 如果共享栈被当前协程占用,要释放占用标志,否则被切换,会执行save_stack_buffer()
590
+ if (co->stack_mem ->occupy_co == co)
591
+ co->stack_mem ->occupy_co = NULL ;
592
+ }
593
+
594
+
561
595
void co_yield_env ( stCoRoutineEnv_t *env )
562
596
{
563
597
Original file line number Diff line number Diff line change @@ -50,6 +50,7 @@ void co_resume( stCoRoutine_t *co );
50
50
void co_yield ( stCoRoutine_t * co );
51
51
void co_yield_ct (); //ct = current thread
52
52
void co_release ( stCoRoutine_t * co );
53
+ void co_reset (stCoRoutine_t * co );
53
54
54
55
stCoRoutine_t * co_self ();
55
56
You can’t perform that action at this time.
0 commit comments