diff --git a/include/cmrx/algo.h b/include/cmrx/algo.h index 9eb85154..91bb093b 100644 --- a/include/cmrx/algo.h +++ b/include/cmrx/algo.h @@ -95,9 +95,9 @@ * items rather than allocation size) */ #define ARRAY_DELETE(_ARRAY, _POS, _SIZE) \ - for (unsigned q = _POS + 1; q < _SIZE; ++q)\ + for (unsigned _q = _POS + 1; _q < _SIZE; ++_q)\ {\ - _ARRAY[q - 1] = _ARRAY[q];\ + _ARRAY[_q - 1] = _ARRAY[_q];\ }\ _SIZE--; @@ -237,7 +237,7 @@ inline uint32_t os_hash_key(uint32_t key) const uint32_t mask = (_MAX) - 1;\ uint32_t pos = hash & mask;\ uint32_t stride = 1;\ - while (_HASHTABLE[pos]._KEY != _VALUE && _HASHTABLE[pos]._KEY != HASH_EMPTY) {\ + while (_HASHTABLE[pos]._KEY != _VALUE && _HASHTABLE[pos]._KEY != (typeof(_HASHTABLE[0]._KEY)) HASH_EMPTY) {\ pos = (pos + stride) & mask;\ stride++;\ }\ diff --git a/src/os/arch/arm/cmsis/arch/assert.h b/src/os/arch/arm/cmsis/arch/assert.h index 08b38eb5..a6bb8599 100644 --- a/src/os/arch/arm/cmsis/arch/assert.h +++ b/src/os/arch/arm/cmsis/arch/assert.h @@ -5,6 +5,7 @@ if (!(cond)) \ {\ asm volatile("BKPT 0xFF\n\t");\ + __builtin_unreachable();\ } #else # define ASSERT(cond) diff --git a/src/os/kernel/notify.c b/src/os/kernel/notify.c index b20cf242..d16a6136 100644 --- a/src/os/kernel/notify.c +++ b/src/os/kernel/notify.c @@ -189,7 +189,10 @@ int os_notify_object(const void * object, Event_t event, uint32_t flags) txn_id = os_txn_start(); candidate_waiter = os_find_notified_thread_waiter(object); - candidate_timer = os_find_timer(os_notification_waiters[candidate_waiter], TIMER_TIMEOUT); + if (candidate_waiter < OS_THREADS) + { + candidate_timer = os_find_timer(os_notification_waiters[candidate_waiter], TIMER_TIMEOUT); + } } while (os_txn_commit(txn_id, TXN_READWRITE) != E_OK); if (candidate_waiter < OS_THREADS) @@ -282,6 +285,17 @@ void cb_syscall_notify_object(const void * object, Thread_t thread, int sleeper, case EVT_TIMEOUT: os_set_syscall_return_value(thread, E_TIMEOUT); + for (unsigned q = 0; q < os_notification_waiters_size; ++q) + { + if (os_notification_waiters[q] == thread) + { + ARRAY_DELETE(os_notification_waiters, q, os_notification_waiters_size); + break; + } + } + notified_thread->wait_object = NULL; + notified_thread->wait_callback = NULL; + break; } } diff --git a/src/os/kernel/sched.c b/src/os/kernel/sched.c index f6957a2f..0d86cac4 100644 --- a/src/os/kernel/sched.c +++ b/src/os/kernel/sched.c @@ -624,6 +624,8 @@ uint32_t os_shutdown(void) os_memory_protection_stop(); os_kernel_shutdown(); + + __builtin_unreachable(); } struct OS_thread_t * os_thread_get(Thread_t thread_id) diff --git a/src/os/kernel/timer.c b/src/os/kernel/timer.c index f5ef3a4d..0aa3bb7e 100644 --- a/src/os/kernel/timer.c +++ b/src/os/kernel/timer.c @@ -118,7 +118,7 @@ static int do_set_timed_event(Txn_t txn, const unsigned slot, const unsigned int sleeper->interval = interval; sleeper->timer_type = type; - if (sleeper_queue[old_queue_offs].resume_time != next_resume || old_queue_offs == TIMER_INVALID_ID) + if (old_queue_offs == TIMER_INVALID_ID || sleeper_queue[old_queue_offs].resume_time != next_resume) { if (old_queue_offs != TIMER_INVALID_ID) {