@@ -136,7 +136,7 @@ typedef struct _jl_ast_context_t {
136
136
value_t ssavalue_sym ;
137
137
value_t slot_sym ;
138
138
jl_module_t * module ; // context module for `current-julia-module-counter`
139
- struct _jl_ast_context_t * next ; // invasive list pointer for getting free contexts
139
+ arraylist_t pinned_objects ;
140
140
} jl_ast_context_t ;
141
141
142
142
static jl_ast_context_t jl_ast_main_ctx ;
@@ -279,27 +279,29 @@ static void jl_init_ast_ctx(jl_ast_context_t *ctx) JL_NOTSAFEPOINT
279
279
ctx -> slot_sym = symbol (fl_ctx , "slot" );
280
280
ctx -> module = NULL ;
281
281
set (symbol (fl_ctx , "*scopewarn-opt*" ), fixnum (jl_options .warn_scope ));
282
+ arraylist_new (& ctx -> pinned_objects , 0 );
282
283
}
283
284
284
285
// There should be no GC allocation while holding this lock
285
286
static uv_mutex_t flisp_lock ;
286
- static jl_ast_context_t * jl_ast_ctx_freed = NULL ;
287
+ int flisp_initialized = 0 ;
288
+ arraylist_t jl_ast_ctx_freed ;
289
+ arraylist_t jl_ast_ctx_used ;
287
290
288
291
static jl_ast_context_t * jl_ast_ctx_enter (jl_module_t * m ) JL_GLOBALLY_ROOTED JL_NOTSAFEPOINT
289
292
{
290
293
JL_SIGATOMIC_BEGIN ();
291
294
uv_mutex_lock (& flisp_lock );
292
- jl_ast_context_t * ctx = jl_ast_ctx_freed ;
293
- if (ctx != NULL ) {
294
- jl_ast_ctx_freed = ctx -> next ;
295
- ctx -> next = NULL ;
296
- }
295
+ jl_ast_context_t * ctx = (jl_ast_context_t * )arraylist_pop (& jl_ast_ctx_freed );
297
296
uv_mutex_unlock (& flisp_lock );
298
297
if (ctx == NULL ) {
299
298
// Construct a new one if we can't find any
300
299
ctx = (jl_ast_context_t * )calloc (1 , sizeof (jl_ast_context_t ));
301
300
jl_init_ast_ctx (ctx );
302
301
}
302
+ uv_mutex_lock (& flisp_lock );
303
+ arraylist_push (& jl_ast_ctx_used , ctx );
304
+ uv_mutex_unlock (& flisp_lock );
303
305
ctx -> module = m ;
304
306
return ctx ;
305
307
}
@@ -308,16 +310,20 @@ static void jl_ast_ctx_leave(jl_ast_context_t *ctx)
308
310
{
309
311
uv_mutex_lock (& flisp_lock );
310
312
ctx -> module = NULL ;
311
- ctx -> next = jl_ast_ctx_freed ;
312
- jl_ast_ctx_freed = ctx ;
313
+ ctx -> pinned_objects .len = 0 ; // clear pinned objects
314
+ arraylist_pop (& jl_ast_ctx_used );
315
+ arraylist_push (& jl_ast_ctx_freed , ctx );
313
316
uv_mutex_unlock (& flisp_lock );
314
317
JL_SIGATOMIC_END ();
315
318
}
316
319
317
320
void jl_init_flisp (void )
318
321
{
319
- if (jl_ast_ctx_freed )
322
+ if (flisp_initialized )
320
323
return ;
324
+ flisp_initialized = 1 ;
325
+ arraylist_new (& jl_ast_ctx_freed , 0 );
326
+ arraylist_new (& jl_ast_ctx_used , 0 );
321
327
uv_mutex_init (& flisp_lock );
322
328
jl_init_ast_ctx (& jl_ast_main_ctx );
323
329
// To match the one in jl_ast_ctx_leave
0 commit comments