@@ -20,21 +20,6 @@ static SEXP mk_error_aio(const int xc, SEXP env) {
20
20
21
21
// aio completion callbacks ----------------------------------------------------
22
22
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
-
38
23
void nano_list_do (nano_list_op listop , nano_aio * saio ) {
39
24
40
25
static nano_node * free_list = NULL ;
@@ -47,7 +32,7 @@ void nano_list_do(nano_list_op listop, nano_aio *saio) {
47
32
break ;
48
33
case FINALIZE :
49
34
nng_mtx_lock (free_mtx );
50
- nano_list_free ( free_list );
35
+ nano_list_do ( FREE , NULL );
51
36
if (saio -> mode == 0x1 ) {
52
37
nng_mtx_unlock (free_mtx );
53
38
nng_aio_free (saio -> aio );
@@ -75,11 +60,23 @@ void nano_list_do(nano_list_op listop, nano_aio *saio) {
75
60
case SHUTDOWN :
76
61
if (free_mtx == NULL ) break ;
77
62
nng_mtx_lock (free_mtx );
78
- nano_list_free ( free_list );
63
+ nano_list_do ( FREE , NULL );
79
64
nng_mtx_unlock (free_mtx );
80
65
nng_mtx_free (free_mtx );
81
66
free_mtx = NULL ;
82
67
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 ;
83
80
}
84
81
85
82
}
0 commit comments