@@ -481,65 +481,19 @@ void jl_start_threads(void)
481
481
482
482
unsigned volatile _threadedregion ; // HACK: keep track of whether it is safe to do IO
483
483
484
- // simple fork/join mode code
485
- JL_DLLEXPORT void jl_threading_run (jl_value_t * func )
484
+ JL_DLLEXPORT void jl_enter_threaded_region (void )
486
485
{
487
- jl_ptls_t ptls = jl_get_ptls_states ();
488
- int8_t gc_state = jl_gc_unsafe_enter (ptls );
489
- size_t world = jl_world_counter ;
490
- jl_method_instance_t * mfunc = jl_lookup_generic (& func , 1 , jl_int32hash_fast (jl_return_address ()), world );
491
- // Ignore constant return value for now.
492
- jl_code_instance_t * fptr = jl_compile_method_internal (mfunc , world );
493
- if (fptr -> invoke == jl_fptr_const_return )
494
- return ;
495
-
496
- size_t nthreads = jl_n_threads ;
497
- jl_svec_t * ts = jl_alloc_svec (nthreads );
498
- JL_GC_PUSH1 (& ts );
499
- jl_value_t * wait_func = jl_get_global (jl_base_module , jl_symbol ("wait" ));
500
- jl_value_t * schd_func = jl_get_global (jl_base_module , jl_symbol ("schedule" ));
501
- // create and schedule all tasks
502
486
_threadedregion += 1 ;
503
- for (int i = 0 ; i < nthreads ; i ++ ) {
504
- jl_value_t * args2 [2 ];
505
- args2 [0 ] = (jl_value_t * )jl_task_type ;
506
- args2 [1 ] = func ;
507
- jl_task_t * t = (jl_task_t * )jl_apply (args2 , 2 );
508
- jl_svecset (ts , i , t );
509
- t -> sticky = 1 ;
510
- t -> tid = i ;
511
- args2 [0 ] = schd_func ;
512
- args2 [1 ] = (jl_value_t * )t ;
513
- jl_apply (args2 , 2 );
514
- if (i == 1 && nthreads > 2 ) {
515
- // hint to threads that work is coming soon
516
- jl_wakeup_thread (-1 );
517
- }
518
- }
519
- // join with all tasks
520
- JL_TRY {
521
- for (int i = 0 ; i < nthreads ; i ++ ) {
522
- jl_value_t * t = jl_svecref (ts , i );
523
- jl_value_t * args [2 ] = { wait_func , t };
524
- jl_apply (args , 2 );
525
- }
526
- }
527
- JL_CATCH {
528
- _threadedregion -= 1 ;
529
- jl_wake_libuv ();
530
- JL_UV_LOCK ();
531
- JL_UV_UNLOCK ();
532
- jl_rethrow ();
533
- }
534
- // make sure no threads are sitting in the event loop
487
+ }
488
+
489
+ JL_DLLEXPORT void jl_exit_threaded_region (void )
490
+ {
535
491
_threadedregion -= 1 ;
536
492
jl_wake_libuv ();
537
493
// make sure no more callbacks will run while user code continues
538
494
// outside thread region and might touch an I/O object.
539
495
JL_UV_LOCK ();
540
496
JL_UV_UNLOCK ();
541
- JL_GC_POP ();
542
- jl_gc_unsafe_leave (ptls , gc_state );
543
497
}
544
498
545
499
0 commit comments