diff --git a/core/atomic_c11.c b/core/atomic_c11.c index 1983c4eeb2..d648a879c9 100644 --- a/core/atomic_c11.c +++ b/core/atomic_c11.c @@ -281,6 +281,7 @@ void __atomic_load_c(size_t size, const void *src, void *dest, int memorder) { (void)memorder; unsigned int mask = irq_disable(); + memcpy(dest, src, size); irq_restore(mask); } @@ -297,6 +298,7 @@ void __atomic_store_c(size_t size, void *dest, const void *src, int memorder) { (void)memorder; unsigned int mask = irq_disable(); + memcpy(dest, src, size); irq_restore(mask); } @@ -315,6 +317,7 @@ void __atomic_exchange_c(size_t size, void *ptr, void *val, void *ret, { (void)memorder; unsigned int mask = irq_disable(); + memcpy(ret, ptr, size); memcpy(ptr, val, size); irq_restore(mask); @@ -361,6 +364,7 @@ bool __atomic_compare_exchange_c(size_t len, void *ptr, void *expected, (void)failure_memorder; unsigned int mask = irq_disable(); bool ret; + if (memcmp(ptr, expected, len) == 0) { memcpy(ptr, desired, len); ret = true; diff --git a/core/include/cib.h b/core/include/cib.h index 087ec1c7a0..875d98c076 100644 --- a/core/include/cib.h +++ b/core/include/cib.h @@ -61,6 +61,7 @@ static inline void cib_init(cib_t *__restrict cib, unsigned int size) assert(!(size & (size - 1))); cib_t c = CIB_INIT(size); + *cib = c; } diff --git a/core/include/macros/units.h b/core/include/macros/units.h index daa04ff4c5..ff3a6ca98d 100644 --- a/core/include/macros/units.h +++ b/core/include/macros/units.h @@ -20,7 +20,7 @@ #define MACROS_UNITS_H #ifdef __cplusplus - extern "C" { +extern "C" { #endif /** diff --git a/core/include/msg_bus.h b/core/include/msg_bus.h index a416e8ff9e..ef1c29c13c 100644 --- a/core/include/msg_bus.h +++ b/core/include/msg_bus.h @@ -101,7 +101,8 @@ static inline uint16_t msg_bus_get_type(const msg_t *msg) { if (msg->sender_pid & MSB_BUS_PID_FLAG) { return msg->type & 0x1F; - } else { + } + else { return msg->type; } } diff --git a/core/init.c b/core/init.c index dbb6a60df0..b39cc48164 100644 --- a/core/init.c +++ b/core/init.c @@ -37,7 +37,8 @@ #include "debug.h" #ifndef CONFIG_BOOT_MSG_STRING -#define CONFIG_BOOT_MSG_STRING "main(): This is RIOT! (Version: " RIOT_VERSION ")" +#define CONFIG_BOOT_MSG_STRING "main(): This is RIOT! (Version: " \ + RIOT_VERSION ")" #endif extern int main(void); @@ -73,7 +74,6 @@ static void *idle_thread(void *arg) return NULL; } - void kernel_init(void) { irq_disable(); diff --git a/core/mbox.c b/core/mbox.c index 6a186cfc00..a1d9ddebd4 100644 --- a/core/mbox.c +++ b/core/mbox.c @@ -36,6 +36,7 @@ static void _wake_waiter(thread_t *thread, unsigned irqstate) "%" PRIkernel_pid ".\n", thread_getpid(), thread->pid); uint16_t process_priority = thread->priority; + irq_restore(irqstate); sched_switch(process_priority); } @@ -46,6 +47,7 @@ static void _wait(list_node_t *wait_list, unsigned irqstate) thread_getpid()); thread_t *me = thread_get_active(); + sched_set_status(me, STATUS_MBOX_BLOCKED); thread_add_to_list(wait_list, me); irq_restore(irqstate); diff --git a/core/msg.c b/core/msg.c index 6c04a51b30..0f356b74d3 100644 --- a/core/msg.c +++ b/core/msg.c @@ -52,6 +52,7 @@ static int queue_msg(thread_t *target, const msg_t *m) DEBUG("queue_msg(): queuing message\n"); msg_t *dest = &target->msg_array[n]; + *dest = *m; #if MODULE_CORE_THREAD_FLAGS target->flags |= THREAD_FLAG_MSG_WAITING; @@ -242,7 +243,7 @@ int msg_send_bus(msg_t *m, msg_bus_t *bus) int count = 0; m->sender_pid = (in_irq ? KERNEL_PID_ISR : thread_getpid()) - | MSB_BUS_PID_FLAG; + | MSB_BUS_PID_FLAG; unsigned state = irq_disable(); @@ -272,6 +273,7 @@ int msg_send_receive(msg_t *m, msg_t *reply, kernel_pid_t target_pid) assert(thread_getpid() != target_pid); unsigned state = irq_disable(); thread_t *me = thread_get_active(); + sched_set_status(me, STATUS_REPLY_BLOCKED); me->wait_data = reply; @@ -302,9 +304,11 @@ int msg_reply(msg_t *m, msg_t *reply) thread_getpid()); /* copy msg to target */ msg_t *target_message = (msg_t *)target->wait_data; + *target_message = *reply; sched_set_status(target, STATUS_PENDING); uint16_t target_prio = target->priority; + irq_restore(state); sched_switch(target_prio); @@ -323,6 +327,7 @@ int msg_reply_int(msg_t *m, msg_t *reply) } msg_t *target_message = (msg_t *)target->wait_data; + *target_message = *reply; sched_set_status(target, STATUS_PENDING); sched_context_switch_request = 1; @@ -394,7 +399,7 @@ static int _msg_receive(msg_t *m, int block) } else { DEBUG("_msg_receive: %" PRIkernel_pid ": _msg_receive(): Waking up " - "waiting thread.\n", thread_getpid()); + "waiting thread.\n", thread_getpid()); thread_t *sender = container_of((clist_node_t *)next, thread_t, rq_entry); diff --git a/core/mutex.c b/core/mutex.c index c8682614f7..cba168ee81 100644 --- a/core/mutex.c +++ b/core/mutex.c @@ -45,9 +45,11 @@ * function into both @ref mutex_lock and @ref mutex_lock_cancelable is, * therefore, beneficial for the majority of applications. */ -static inline __attribute__((always_inline)) void _block(mutex_t *mutex, unsigned irq_state) +static inline __attribute__((always_inline)) void _block(mutex_t *mutex, + unsigned irq_state) { thread_t *me = thread_get_active(); + DEBUG("PID[%" PRIkernel_pid "] mutex_lock() Adding node to mutex queue: " "prio: %" PRIu32 "\n", thread_getpid(), (uint32_t)me->priority); sched_set_status(me, STATUS_MUTEX_BLOCKED); @@ -97,6 +99,7 @@ int mutex_lock_cancelable(mutex_cancel_t *mc) } mutex_t *mutex = mc->mutex; + if (mutex->queue.next == NULL) { /* mutex is unlocked. */ mutex->queue.next = MUTEX_LOCKED; @@ -111,7 +114,7 @@ int mutex_lock_cancelable(mutex_cancel_t *mc) DEBUG("PID[%" PRIkernel_pid "] mutex_lock_cancelable() " "cancelled.\n", thread_getpid()); } - return (mc->cancelled) ? -ECANCELED: 0; + return (mc->cancelled) ? -ECANCELED : 0; } } @@ -148,6 +151,7 @@ void mutex_unlock(mutex_t *mutex) } uint16_t process_priority = process->priority; + irq_restore(irqstate); sched_switch(process_priority); } @@ -185,10 +189,12 @@ void mutex_unlock_and_sleep(mutex_t *mutex) void mutex_cancel(mutex_cancel_t *mc) { unsigned irq_state = irq_disable(); + mc->cancelled = 1; mutex_t *mutex = mc->mutex; thread_t *thread = mc->thread; + if (thread_is_active(thread)) { /* thread is still running or about to run, so it will check * `mc-cancelled` in time */ @@ -197,8 +203,8 @@ void mutex_cancel(mutex_cancel_t *mc) } if ((mutex->queue.next != MUTEX_LOCKED) - && (mutex->queue.next != NULL) - && list_remove(&mutex->queue, (list_node_t *)&thread->rq_entry)) { + && (mutex->queue.next != NULL) + && list_remove(&mutex->queue, (list_node_t *)&thread->rq_entry)) { /* Thread was queued and removed from list, wake it up */ if (mutex->queue.next == NULL) { mutex->queue.next = MUTEX_LOCKED; diff --git a/core/panic.c b/core/panic.c index ec8c609d04..6f04d79481 100644 --- a/core/panic.c +++ b/core/panic.c @@ -48,8 +48,10 @@ const char assert_crash_message[] = "FAILED ASSERTION."; /* flag preventing "recursive crash printing loop" */ static int crashed = 0; -void __attribute__((weak)) panic_arch(void) {} -void __attribute__((weak)) panic_app(core_panic_t crash_code, const char *message) +void __attribute__((weak)) panic_arch(void) +{} +void __attribute__((weak)) panic_app(core_panic_t crash_code, + const char *message) { (void)crash_code; (void)message; diff --git a/core/thread.c b/core/thread.c index e3ae5ae8c4..8e318c2f82 100644 --- a/core/thread.c +++ b/core/thread.c @@ -102,6 +102,7 @@ void thread_sleep(void) } unsigned state = irq_disable(); + sched_set_status(thread_get_active(), STATUS_SLEEPING); irq_restore(state); thread_yield_higher(); @@ -183,6 +184,7 @@ uintptr_t thread_measure_stack_free(const char *stack) } uintptr_t space_free = (uintptr_t)stackp - (uintptr_t)stack; + return space_free; } #endif @@ -199,7 +201,7 @@ kernel_pid_t thread_create(char *stack, int stacksize, uint8_t priority, int total_stacksize = stacksize; #endif #ifndef CONFIG_THREAD_NAMES - (void) name; + (void)name; #endif /* align the stack on a 16/32bit boundary */ @@ -342,7 +344,7 @@ const char *thread_state_to_string(thread_status_t state) const char *name = state_names[state] ? state_names[state] : NULL; assert(name != NULL); /* if compiling with assertions, this is an error that - indicates that the table above is incomplete */ + indicates that the table above is incomplete */ return (name != NULL) ? name : STATE_NAME_UNKNOWN; } diff --git a/core/thread_flags.c b/core/thread_flags.c index ff3b91eea6..1d4db08f10 100644 --- a/core/thread_flags.c +++ b/core/thread_flags.c @@ -18,7 +18,6 @@ * @} */ - #include "thread_flags.h" #include "irq.h" #include "thread.h" @@ -26,7 +25,8 @@ #define ENABLE_DEBUG 0 #include "debug.h" -static inline int __attribute__((always_inline)) _thread_flags_wake(thread_t *thread) +static inline int __attribute__((always_inline)) _thread_flags_wake( + thread_t *thread) { unsigned wakeup; thread_flags_t mask = (uint16_t)(unsigned)thread->wait_data; @@ -118,6 +118,7 @@ thread_flags_t thread_flags_wait_one(thread_flags_t mask) _thread_flags_wait_any(mask); thread_t *me = thread_get_active(); thread_flags_t tmp = me->flags & mask; + /* clear all but least significant bit */ tmp &= (~tmp + 1); return _thread_flags_clear_atomic(me, tmp); @@ -146,6 +147,7 @@ void thread_flags_set(thread_t *thread, thread_flags_t mask) DEBUG("thread_flags_set(): setting 0x%08x for pid %" PRIkernel_pid "\n", mask, thread->pid); unsigned state = irq_disable(); + thread->flags |= mask; if (_thread_flags_wake(thread)) { irq_restore(state);