1414extern  "C"  {
1515#endif 
1616
17- #define  JULIA_ENABLE_PARTR 
17+ 
18+ // thread sleep state 
19+ 
20+ static  int16_t  sleep_check_state ; // status of the multi-queue. possible values: 
21+ 
22+ // no thread should be sleeping--there might be work in the multi-queue. 
23+ static  const  int16_t  not_sleeping  =  0 ;
24+ 
25+ // it is acceptable for a thread to be sleeping if its sticky queue is empty. 
26+ // sleep_check_state == sleeping + 1 + tid means thread tid is checking the multi-queue 
27+ // to see if it is safe to transition to sleeping. 
28+ static  const  int16_t  sleeping  =  1 ;
29+ 
1830
1931#ifdef  JULIA_ENABLE_THREADING 
2032
@@ -46,16 +58,6 @@ static int16_t heap_p;
4658/* unbias state for the RNG */ 
4759static  uint64_t  cong_unbias ;
4860
49- static  int16_t  sleep_check_state ; // status of the multi-queue. possible values: 
50- 
51- // no thread should be sleeping--there might be work in the multi-queue. 
52- static  const  int16_t  not_sleeping  =  0 ;
53- 
54- // it is acceptable for a thread to be sleeping if its sticky queue is empty. 
55- // sleep_check_state == sleeping + 1 + tid means thread tid is checking the multi-queue 
56- // to see if it is safe to transition to sleeping. 
57- static  const  int16_t  sleeping  =  1 ;
58- 
5961
6062static  inline  void  multiq_init (void )
6163{
@@ -178,6 +180,15 @@ static inline jl_task_t *multiq_deletemin(void)
178180}
179181
180182
183+ void  jl_gc_mark_enqueued_tasks (jl_gc_mark_cache_t  * gc_cache , jl_gc_mark_sp_t  * sp )
184+ {
185+     int16_t  i , j ;
186+     for  (i  =  0 ; i  <  heap_p ; ++ i )
187+         for  (j  =  0 ; j  <  heaps [i ].ntasks ; ++ j )
188+             jl_gc_mark_queue_obj_explicit (gc_cache , sp , (jl_value_t  * )heaps [i ].tasks [j ]);
189+ }
190+ 
191+ 
181192static  int  multiq_check_empty (void )
182193{
183194    int16_t  i ;
@@ -275,6 +286,13 @@ void jl_threadfun(void *arg)
275286}
276287
277288
289+ // enqueue the specified task for execution 
290+ JL_DLLEXPORT  void  jl_enqueue_task (jl_task_t  * task )
291+ {
292+     multiq_insert (task , task -> prio );
293+ }
294+ 
295+ 
278296//  sleep_check_after_threshold() -- if sleep_threshold ns have passed, return 1 
279297static  int  sleep_check_after_threshold (uint64_t  * start_cycles )
280298{
@@ -301,6 +319,22 @@ static void wake_thread(int16_t self, int16_t tid)
301319    }
302320}
303321
322+ #else  // JULIA_ENABLE_THREADING 
323+ 
324+ static  int  sleep_check_now (int16_t  tid )
325+ {
326+     (void )tid ;
327+     return  1 ;
328+ }
329+ 
330+ static  int  sleep_check_after_threshold (uint64_t  * start_cycles )
331+ {
332+     (void )start_cycles ;
333+     return  1 ;
334+ }
335+ 
336+ #endif 
337+ 
304338/* ensure thread tid is awake if necessary */ 
305339JL_DLLEXPORT  void  jl_wakeup_thread (int16_t  tid )
306340{
@@ -311,6 +345,7 @@ JL_DLLEXPORT void jl_wakeup_thread(int16_t tid)
311345        if  (uvlock  ==  self )
312346            uv_stop (jl_global_event_loop ());
313347    }
348+ #ifdef  JULIA_ENABLE_THREADING 
314349    else  {
315350        // check if the other threads might be sleeping 
316351        if  (jl_atomic_load_acquire (& sleep_check_state ) !=  not_sleeping ) {
@@ -333,13 +368,7 @@ JL_DLLEXPORT void jl_wakeup_thread(int16_t tid)
333368                jl_wake_libuv ();
334369        }
335370    }
336- }
337- 
338- 
339- // enqueue the specified task for execution 
340- JL_DLLEXPORT  void  jl_enqueue_task (jl_task_t  * task )
341- {
342-     multiq_insert (task , task -> prio );
371+ #endif 
343372}
344373
345374
@@ -356,7 +385,11 @@ static jl_task_t *get_next_task(jl_value_t *getsticky)
356385        }
357386        return  task ;
358387    }
388+ #ifdef  JULIA_ENABLE_THREADING 
359389    return  multiq_deletemin ();
390+ #else 
391+     return  NULL ;
392+ #endif 
360393}
361394
362395extern  volatile  unsigned  _threadedregion ;
@@ -373,11 +406,13 @@ JL_DLLEXPORT jl_task_t *jl_task_get_next(jl_value_t *getsticky)
373406        if  (task )
374407            return  task ;
375408
409+ #ifdef  JULIA_ENABLE_THREADING 
376410        jl_cpu_pause ();
377411        if  (!multiq_check_empty ()) {
378412            start_cycles  =  0 ;
379413            continue ;
380414        }
415+ #endif 
381416
382417        jl_cpu_pause ();
383418        if  (sleep_check_after_threshold (& start_cycles ) ||  (!_threadedregion  &&  ptls -> tid  ==  0 )) {
@@ -465,17 +500,6 @@ JL_DLLEXPORT jl_task_t *jl_task_get_next(jl_value_t *getsticky)
465500    }
466501}
467502
468- 
469- void  jl_gc_mark_enqueued_tasks (jl_gc_mark_cache_t  * gc_cache , jl_gc_mark_sp_t  * sp )
470- {
471-     int16_t  i , j ;
472-     for  (i  =  0 ; i  <  heap_p ; ++ i )
473-         for  (j  =  0 ; j  <  heaps [i ].ntasks ; ++ j )
474-             jl_gc_mark_queue_obj_explicit (gc_cache , sp , (jl_value_t  * )heaps [i ].tasks [j ]);
475- }
476- 
477- #endif  // JULIA_ENABLE_THREADING 
478- 
479503#ifdef  __cplusplus 
480504}
481505#endif 
0 commit comments