@@ -20,21 +20,6 @@ static SEXP mk_error_aio(const int xc, SEXP env) {
2020
2121// aio completion callbacks ----------------------------------------------------
2222
23- static inline void nano_list_free (nano_node * list ) {
24-
25- while (list != NULL ) {
26- nano_node * current = list ;
27- list = list -> next ;
28- nano_aio * saio = (nano_aio * ) current -> data ;
29- nng_aio_free (saio -> aio );
30- if (saio -> data != NULL )
31- free (saio -> data );
32- free (saio );
33- free (current );
34- }
35-
36- }
37-
3823void nano_list_do (nano_list_op listop , nano_aio * saio ) {
3924
4025 static nano_node * free_list = NULL ;
@@ -47,7 +32,7 @@ void nano_list_do(nano_list_op listop, nano_aio *saio) {
4732 break ;
4833 case FINALIZE :
4934 nng_mtx_lock (free_mtx );
50- nano_list_free ( free_list );
35+ nano_list_do ( FREE , NULL );
5136 if (saio -> mode == 0x1 ) {
5237 nng_mtx_unlock (free_mtx );
5338 nng_aio_free (saio -> aio );
@@ -75,11 +60,23 @@ void nano_list_do(nano_list_op listop, nano_aio *saio) {
7560 case SHUTDOWN :
7661 if (free_mtx == NULL ) break ;
7762 nng_mtx_lock (free_mtx );
78- nano_list_free ( free_list );
63+ nano_list_do ( FREE , NULL );
7964 nng_mtx_unlock (free_mtx );
8065 nng_mtx_free (free_mtx );
8166 free_mtx = NULL ;
8267 break ;
68+ case FREE : // must be entered under lock
69+ while (free_list != NULL ) {
70+ nano_node * current = free_list ;
71+ free_list = free_list -> next ;
72+ nano_aio * saio = (nano_aio * ) current -> data ;
73+ nng_aio_free (saio -> aio );
74+ if (saio -> data != NULL )
75+ free (saio -> data );
76+ free (saio );
77+ free (current );
78+ }
79+ break ;
8380 }
8481
8582}
0 commit comments