kernel: Using boolean constants instead of 0 or 1

MISRA C requires that every controlling expression of and if or while
statement have a boolean type.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
This commit is contained in:
Flavio Ceolin 2018-09-17 15:56:06 -07:00 committed by Anas Nashif
commit b3d9202704
9 changed files with 20 additions and 14 deletions

View file

@ -17,6 +17,7 @@
#include <toolchain.h> #include <toolchain.h>
#include <linker/sections.h> #include <linker/sections.h>
#include <syscall_handler.h> #include <syscall_handler.h>
#include <stdbool.h>
extern struct k_alert _k_alert_list_start[]; extern struct k_alert _k_alert_list_start[];
extern struct k_alert _k_alert_list_end[]; extern struct k_alert _k_alert_list_end[];
@ -48,7 +49,7 @@ void _alert_deliver(struct k_work *work)
{ {
struct k_alert *alert = CONTAINER_OF(work, struct k_alert, work_item); struct k_alert *alert = CONTAINER_OF(work, struct k_alert, work_item);
while (1) { while (true) {
if ((alert->handler)(alert) == 0) { if ((alert->handler)(alert) == 0) {
/* do nothing -- handler has processed the alert */ /* do nothing -- handler has processed the alert */
} else { } else {

View file

@ -11,6 +11,7 @@
#include <drivers/system_timer.h> #include <drivers/system_timer.h>
#include <wait_q.h> #include <wait_q.h>
#include <power.h> #include <power.h>
#include <stdbool.h>
#if defined(CONFIG_TICKLESS_IDLE) #if defined(CONFIG_TICKLESS_IDLE)
/* /*
@ -20,7 +21,7 @@
s32_t _sys_idle_threshold_ticks = CONFIG_TICKLESS_IDLE_THRESH; s32_t _sys_idle_threshold_ticks = CONFIG_TICKLESS_IDLE_THRESH;
#if defined(CONFIG_TICKLESS_KERNEL) #if defined(CONFIG_TICKLESS_KERNEL)
#define _must_enter_tickless_idle(ticks) (1) #define _must_enter_tickless_idle(ticks) (true)
#else #else
#define _must_enter_tickless_idle(ticks) \ #define _must_enter_tickless_idle(ticks) \
((ticks == K_FOREVER) || (ticks >= _sys_idle_threshold_ticks)) ((ticks == K_FOREVER) || (ticks >= _sys_idle_threshold_ticks))
@ -47,7 +48,6 @@ void __attribute__((weak)) _sys_soc_resume_from_deep_sleep(void)
{ {
} }
#endif #endif
/** /**
* *
* @brief Indicate that kernel is idling in tickless mode * @brief Indicate that kernel is idling in tickless mode
@ -64,7 +64,7 @@ static void set_kernel_idle_time_in_ticks(s32_t ticks)
_kernel.idle = ticks; _kernel.idle = ticks;
} }
#else #else
#define set_kernel_idle_time_in_ticks(x) do { } while (0) #define set_kernel_idle_time_in_ticks(x) do { } while (false)
#endif #endif
#ifndef CONFIG_SMP #ifndef CONFIG_SMP
@ -175,7 +175,7 @@ void idle(void *unused1, void *unused2, void *unused3)
* busy waiting is needed to prevent lock contention. Long * busy waiting is needed to prevent lock contention. Long
* term we need to wake up idle CPUs with an IPI. * term we need to wake up idle CPUs with an IPI.
*/ */
while (1) { while (true) {
k_busy_wait(100); k_busy_wait(100);
k_yield(); k_yield();
} }

View file

@ -15,6 +15,7 @@
#define ZEPHYR_KERNEL_INCLUDE_KERNEL_INTERNAL_H_ #define ZEPHYR_KERNEL_INCLUDE_KERNEL_INTERNAL_H_
#include <kernel.h> #include <kernel.h>
#include <stdbool.h>
#ifndef _ASMLANGUAGE #ifndef _ASMLANGUAGE
@ -198,7 +199,7 @@ extern void _thread_monitor_exit(struct k_thread *thread);
#else #else
#define _thread_monitor_exit(thread) \ #define _thread_monitor_exit(thread) \
do {/* nothing */ \ do {/* nothing */ \
} while (0) } while (false)
#endif /* CONFIG_THREAD_MONITOR */ #endif /* CONFIG_THREAD_MONITOR */
extern void smp_init(void); extern void smp_init(void);

View file

@ -14,6 +14,7 @@
#include <kernel.h> #include <kernel.h>
#include <misc/printk.h> #include <misc/printk.h>
#include <kernel_internal.h> #include <kernel_internal.h>
#include <stdbool.h>
extern const _k_syscall_handler_t _k_syscall_table[K_SYSCALL_LIMIT]; extern const _k_syscall_handler_t _k_syscall_table[K_SYSCALL_LIMIT];
@ -259,7 +260,7 @@ extern int z_user_string_copy(char *dst, char *src, size_t maxlen);
if (expr) { \ if (expr) { \
_arch_syscall_oops(ssf); \ _arch_syscall_oops(ssf); \
} \ } \
} while (0) } while (false)
static inline __attribute__((warn_unused_result)) __printf_like(2, 3) static inline __attribute__((warn_unused_result)) __printf_like(2, 3)
bool z_syscall_verify_msg(bool expr, const char *fmt, ...) bool z_syscall_verify_msg(bool expr, const char *fmt, ...)

View file

@ -32,6 +32,7 @@
#include <entropy.h> #include <entropy.h>
#include <logging/log_ctrl.h> #include <logging/log_ctrl.h>
#include <tracing.h> #include <tracing.h>
#include <stdbool.h>
/* kernel build timestamp items */ /* kernel build timestamp items */
#define BUILD_TIMESTAMP "BUILD: " __DATE__ " " __TIME__ #define BUILD_TIMESTAMP "BUILD: " __DATE__ " " __TIME__
@ -55,7 +56,7 @@ static const unsigned int boot_delay;
#endif #endif
#if !defined(CONFIG_BOOT_BANNER) #if !defined(CONFIG_BOOT_BANNER)
#define PRINT_BOOT_BANNER() do { } while (0) #define PRINT_BOOT_BANNER() do { } while (false)
#else #else
#define PRINT_BOOT_BANNER() printk("***** " BOOT_BANNER " *****\n") #define PRINT_BOOT_BANNER() printk("***** " BOOT_BANNER " *****\n")
#endif #endif
@ -493,7 +494,7 @@ FUNC_NORETURN void _Cstart(void)
bg_thread_main(NULL, NULL, NULL); bg_thread_main(NULL, NULL, NULL);
irq_lock(); irq_lock();
while (1) { while (true) {
} }
#endif #endif

View file

@ -10,6 +10,7 @@
#include <init.h> #include <init.h>
#include <string.h> #include <string.h>
#include <misc/__assert.h> #include <misc/__assert.h>
#include <stdbool.h>
/* Linker-defined symbols bound the static pool structs */ /* Linker-defined symbols bound the static pool structs */
extern struct k_mem_pool _k_mem_pool_list_start[]; extern struct k_mem_pool _k_mem_pool_list_start[];
@ -59,7 +60,7 @@ int k_mem_pool_alloc(struct k_mem_pool *p, struct k_mem_block *block,
end = _tick_get() + _ms_to_ticks(timeout); end = _tick_get() + _ms_to_ticks(timeout);
} }
while (1) { while (true) {
u32_t level_num, block_num; u32_t level_num, block_num;
/* There is a "managed race" in alloc that can fail /* There is a "managed race" in alloc that can fail

View file

@ -252,7 +252,7 @@ static inline void handle_timeouts(s32_t ticks)
_handle_expired_timeouts(&expired); _handle_expired_timeouts(&expired);
} }
#else #else
#define handle_timeouts(ticks) do { } while ((0)) #define handle_timeouts(ticks) do { } while (false)
#endif #endif
#ifdef CONFIG_TIMESLICING #ifdef CONFIG_TIMESLICING
@ -295,7 +295,7 @@ static void handle_time_slicing(s32_t ticks)
#endif #endif
} }
#else #else
#define handle_time_slicing(ticks) do { } while (0) #define handle_time_slicing(ticks) do { } while (false)
#endif #endif
/** /**

View file

@ -661,7 +661,7 @@ void k_thread_access_grant(struct k_thread *thread, ...)
va_list args; va_list args;
va_start(args, thread); va_start(args, thread);
while (1) { while (true) {
void *object = va_arg(args, void *); void *object = va_arg(args, void *);
if (object == NULL) { if (object == NULL) {
break; break;

View file

@ -14,6 +14,7 @@
#include <kernel_structs.h> #include <kernel_structs.h>
#include <wait_q.h> #include <wait_q.h>
#include <errno.h> #include <errno.h>
#include <stdbool.h>
static void work_q_main(void *work_q_ptr, void *p2, void *p3) static void work_q_main(void *work_q_ptr, void *p2, void *p3)
{ {
@ -22,7 +23,7 @@ static void work_q_main(void *work_q_ptr, void *p2, void *p3)
ARG_UNUSED(p2); ARG_UNUSED(p2);
ARG_UNUSED(p3); ARG_UNUSED(p3);
while (1) { while (true) {
struct k_work *work; struct k_work *work;
k_work_handler_t handler; k_work_handler_t handler;