Skip to content

Commit 25b9f4d

Browse files
petermmampcode-com
andcommitted
Fix no-SMP scheduler watchdog slot selection
The scheduler watchdog only needs a slot index, and on no-SMP builds that slot is always 0. Keep smp_scheduler_id() as an SMP-only API and choose slot 0 locally in scheduler.c instead of providing a no-SMP stub in smp.h. This fixes no-SMP builds without adding a GlobalContext typedef or watchdog-specific fallback to the SMP abstraction. Signed-off-by: Peter M <petermm@gmail.com> Amp-Thread-ID: https://ampcode.com/threads/T-019cffb9-55d6-70d2-8382-88fd927bdc77 Co-authored-by: Amp <amp@ampcode.com>
1 parent 3d7409f commit 25b9f4d

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

src/libAtomVM/scheduler.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,20 @@ static int update_timer_list(GlobalContext *global)
5858
return (int) wait_timeout_ms;
5959
}
6060

61-
static inline void scheduler_record_progress(GlobalContext *global)
61+
static inline int scheduler_watchdog_slot(GlobalContext *global)
6262
{
63+
#ifndef AVM_NO_SMP
6364
int scheduler_id = smp_scheduler_id(global);
64-
if (scheduler_id < 0) {
65-
scheduler_id = 0;
66-
}
65+
return scheduler_id < 0 ? 0 : scheduler_id;
66+
#else
67+
UNUSED(global);
68+
return 0;
69+
#endif
70+
}
71+
72+
static inline void scheduler_record_progress(GlobalContext *global)
73+
{
74+
int scheduler_id = scheduler_watchdog_slot(global);
6775
if (UNLIKELY(scheduler_id >= AVM_SCHEDULER_WATCHDOG_MAX_SLOTS)) {
6876
fprintf(stderr, "WARNING: scheduler_id %d exceeds AVM_SCHEDULER_WATCHDOG_MAX_SLOTS (%d), watchdog coverage lost\n",
6977
scheduler_id, AVM_SCHEDULER_WATCHDOG_MAX_SLOTS);

src/libAtomVM/smp.h

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,8 @@ bool smp_is_main_thread(GlobalContext *glb);
265265
/**
266266
* @brief Return a small stable identifier for the current scheduler thread.
267267
*
268-
* @details In non-SMP builds this is always 0. In SMP builds, the main
269-
* scheduler is 0 and other schedulers return a positive small integer.
268+
* @details The main scheduler is 0 and other schedulers return a positive
269+
* small integer.
270270
*/
271271
int smp_scheduler_id(GlobalContext *glb);
272272

@@ -298,11 +298,6 @@ int smp_scheduler_id(GlobalContext *glb);
298298
#define SMP_RWLOCK_WRLOCK(lock)
299299
#define SMP_RWLOCK_UNLOCK(lock)
300300

301-
static inline int smp_scheduler_id(GlobalContext *glb)
302-
{
303-
UNUSED(glb);
304-
return 0;
305-
}
306301
#endif
307302

308303
#endif

0 commit comments

Comments
 (0)