Skip to content

Commit dea4940

Browse files
authored
fix build with JULIA_ENABLE_THREADING==0 (#32168)
1 parent 93972d1 commit dea4940

File tree

5 files changed

+62
-30
lines changed

5 files changed

+62
-30
lines changed

base/task.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ end
412412
function enq_work(t::Task)
413413
(t.state == :runnable && t.queue === nothing) || error("schedule: Task not runnable")
414414
tid = Threads.threadid(t)
415-
if t.sticky || tid != 0
415+
if t.sticky || tid != 0 || Threads.nthreads() == 1
416416
if tid == 0
417417
tid = Threads.threadid()
418418
end

src/gc.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2499,7 +2499,9 @@ static void mark_roots(jl_gc_mark_cache_t *gc_cache, jl_gc_mark_sp_t *sp)
24992499
gc_mark_queue_obj(gc_cache, sp, jl_main_module);
25002500

25012501
// tasks
2502+
#ifdef JULIA_ENABLE_THREADING
25022503
jl_gc_mark_enqueued_tasks(gc_cache, sp);
2504+
#endif
25032505

25042506
// invisible builtin values
25052507
if (jl_an_empty_vec_any != NULL)

src/partr.c

Lines changed: 53 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,19 @@
1414
extern "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 */
4759
static 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

6062
static 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+
181192
static 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
279297
static 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 */
305339
JL_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

362395
extern 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

src/task.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,8 @@ JL_DLLEXPORT void jl_switchto(jl_task_t **pt)
374374
assert(t->tid == ptls->tid);
375375
if (!t->sticky && !t->copy_stack)
376376
t->tid = -1;
377+
#elif defined(NDEBUG)
378+
(void)refetch_ptls();
377379
#else
378380
assert(ptls == refetch_ptls());
379381
#endif

src/threading.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,15 +505,19 @@ JL_DLLEXPORT void jl_threading_run(jl_value_t *func)
505505
args2[0] = schd_func;
506506
args2[1] = (jl_value_t*)t;
507507
jl_apply(args2, 2);
508+
#ifdef JULIA_ENABLE_THREADING
508509
if (i == 1) {
509510
// let threads know work is coming (optimistic)
510511
jl_wakeup_thread(-1);
511512
}
513+
#endif
512514
}
515+
#ifdef JULIA_ENABLE_THREADING
513516
if (nthreads > 2) {
514517
// let threads know work is ready (guaranteed)
515518
jl_wakeup_thread(-1);
516519
}
520+
#endif
517521
// join with all tasks
518522
JL_TRY {
519523
for (int i = 0; i < nthreads; i++) {

0 commit comments

Comments
 (0)