1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-12-20 03:53:49 +01:00

Merge pull request #18573 from maribu/core/sched.c

core/sched.c: fix undefined behavior on 8-bit/16-bit
This commit is contained in:
Koen Zandberg 2022-09-10 11:48:52 +02:00 committed by GitHub
commit 7fce01303b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -23,12 +23,13 @@
#include <stdint.h>
#include <inttypes.h>
#include "sched.h"
#include "clist.h"
#include "assert.h"
#include "bitarithm.h"
#include "clist.h"
#include "irq.h"
#include "thread.h"
#include "log.h"
#include "sched.h"
#include "thread.h"
#ifdef MODULE_MPU_STACK_GUARD
#include "mpu.h"
@ -58,6 +59,8 @@ volatile kernel_pid_t sched_active_pid = KERNEL_PID_UNDEF;
volatile thread_t *sched_threads[KERNEL_PID_LAST + 1];
volatile int sched_num_threads = 0;
static_assert(SCHED_PRIO_LEVELS <= 32, "SCHED_PRIO_LEVELS may at most be 32");
FORCE_USED_SECTION
const uint8_t max_threads = ARRAY_SIZE(sched_threads);
@ -92,7 +95,7 @@ static inline void _set_runqueue_bit(uint8_t priority)
#if defined(BITARITHM_HAS_CLZ)
runqueue_bitcache |= BIT31 >> priority;
#else
runqueue_bitcache |= 1 << priority;
runqueue_bitcache |= 1UL << priority;
#endif
}
@ -101,7 +104,7 @@ static inline void _clear_runqueue_bit(uint8_t priority)
#if defined(BITARITHM_HAS_CLZ)
runqueue_bitcache &= ~(BIT31 >> priority);
#else
runqueue_bitcache &= ~(1 << priority);
runqueue_bitcache &= ~(1UL << priority);
#endif
}