summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Hughes <tomhughes@chromium.org>2021-11-03 22:40:26 +0000
committerCommit Bot <commit-bot@chromium.org>2021-11-09 20:01:00 +0000
commit107bea02fefdc4286e929d5cde48b2a57a0ded21 (patch)
tree2425f5da2266263843be341dda7ef1d3bf80699d
parentbb8a41cb2ba8b5c66a4035772173eb0057a9096c (diff)
downloadchrome-ec-107bea02fefdc4286e929d5cde48b2a57a0ded21.tar.gz
task: Use bool for truthy return types
Using bool makes it clear that the function returns "true" or "false", rather than any integer. It also avoids the need to use "!!" to set the value to 0 or 1, since the compiler ensures that "bool" is always a 0 or 1, even if another value is assigned. BRANCH=none BUG=b:172020503 TEST=make buildall Signed-off-by: Tom Hughes <tomhughes@chromium.org> Change-Id: I164e5c03c23fa2f0ffb61e87f5613e080814ce10 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3262593 Reviewed-by: Keith Short <keithshort@chromium.org>
-rw-r--r--core/cortex-m/task.c4
-rw-r--r--core/cortex-m0/task.c4
-rw-r--r--core/host/task.c12
-rw-r--r--core/minute-ia/task.c8
-rw-r--r--core/nds32/task.c6
-rw-r--r--core/riscv-rv32i/task.c8
-rw-r--r--include/task.h6
-rw-r--r--zephyr/shim/src/tasks.c2
8 files changed, 25 insertions, 25 deletions
diff --git a/core/cortex-m/task.c b/core/cortex-m/task.c
index b86750bd67..fa5642cca6 100644
--- a/core/cortex-m/task.c
+++ b/core/cortex-m/task.c
@@ -227,7 +227,7 @@ void interrupt_enable(void)
asm("cpsie i");
}
-inline int is_interrupt_enabled(void)
+inline bool is_interrupt_enabled(void)
{
int primask;
@@ -237,7 +237,7 @@ inline int is_interrupt_enabled(void)
return !(primask & 0x1);
}
-inline int in_interrupt_context(void)
+inline bool in_interrupt_context(void)
{
int ret;
asm("mrs %0, ipsr \n" /* read exception number */
diff --git a/core/cortex-m0/task.c b/core/cortex-m0/task.c
index 2c1bf2a8c4..af1886005b 100644
--- a/core/cortex-m0/task.c
+++ b/core/cortex-m0/task.c
@@ -161,7 +161,7 @@ void interrupt_enable(void)
asm("cpsie i");
}
-inline int is_interrupt_enabled(void)
+inline bool is_interrupt_enabled(void)
{
int primask;
@@ -171,7 +171,7 @@ inline int is_interrupt_enabled(void)
return !(primask & 0x1);
}
-inline int in_interrupt_context(void)
+inline bool in_interrupt_context(void)
{
int ret;
asm("mrs %0, ipsr\n" /* read exception number */
diff --git a/core/host/task.c b/core/host/task.c
index 70ce3e006f..44d8082d82 100644
--- a/core/host/task.c
+++ b/core/host/task.c
@@ -47,7 +47,7 @@ static int task_started;
static sem_t interrupt_sem;
static pthread_mutex_t interrupt_lock;
static pthread_t interrupt_thread;
-static int in_interrupt;
+static bool in_interrupt;
static int interrupt_disabled;
static void (*pending_isr)(void);
static int generator_sleeping;
@@ -119,9 +119,9 @@ void task_pre_init(void)
/* Nothing */
}
-int in_interrupt_context(void)
+bool in_interrupt_context(void)
{
- return !!in_interrupt;
+ return in_interrupt;
}
test_mockable void interrupt_disable(void)
@@ -138,17 +138,17 @@ test_mockable void interrupt_enable(void)
pthread_mutex_unlock(&interrupt_lock);
}
-inline int is_interrupt_enabled(void)
+inline bool is_interrupt_enabled(void)
{
return !interrupt_disabled;
}
static void _task_execute_isr(int sig)
{
- in_interrupt = 1;
+ in_interrupt = true;
pending_isr();
sem_post(&interrupt_sem);
- in_interrupt = 0;
+ in_interrupt = false;
}
void task_register_interrupt(void)
diff --git a/core/minute-ia/task.c b/core/minute-ia/task.c
index dc0d72fb23..cde3d80e12 100644
--- a/core/minute-ia/task.c
+++ b/core/minute-ia/task.c
@@ -173,7 +173,7 @@ void interrupt_enable(void)
__asm__ __volatile__ ("sti");
}
-inline int is_interrupt_enabled(void)
+inline bool is_interrupt_enabled(void)
{
uint32_t eflags = 0;
@@ -182,12 +182,12 @@ inline int is_interrupt_enabled(void)
: "=r"(eflags));
/* Check Interrupt Enable flag */
- return !!(eflags & 0x200);
+ return eflags & 0x200;
}
-inline int in_interrupt_context(void)
+inline bool in_interrupt_context(void)
{
- return !!__in_isr;
+ return __in_isr;
}
task_id_t task_get_current(void)
diff --git a/core/nds32/task.c b/core/nds32/task.c
index 5b4fe86876..3457af2bb5 100644
--- a/core/nds32/task.c
+++ b/core/nds32/task.c
@@ -224,17 +224,17 @@ void __ram_code interrupt_enable(void)
asm volatile ("mtsr %0, $INT_MASK" : : "r"(val));
}
-inline int is_interrupt_enabled(void)
+inline bool is_interrupt_enabled(void)
{
uint32_t val = 0;
asm volatile ("mfsr %0, $INT_MASK" : "=r"(val));
/* Interrupts are enabled if any of HW2 ~ HW15 is enabled */
- return !!(val & 0xFFFC);
+ return val & 0xFFFC;
}
-inline int in_interrupt_context(void)
+inline bool in_interrupt_context(void)
{
/* check INTL (Interrupt Stack Level) bits */
return get_psw() & PSW_INTL_MASK;
diff --git a/core/riscv-rv32i/task.c b/core/riscv-rv32i/task.c
index ef1595eaeb..89d7671fe1 100644
--- a/core/riscv-rv32i/task.c
+++ b/core/riscv-rv32i/task.c
@@ -199,22 +199,22 @@ void __ram_code interrupt_enable(void)
asm volatile ("csrs mie, t0");
}
-inline int is_interrupt_enabled(void)
+inline bool is_interrupt_enabled(void)
{
int mie = 0;
asm volatile ("csrr %0, mie" : "=r"(mie));
/* Check if MEIE bit is set in MIE register */
- return !!(mie & 0x800);
+ return mie & 0x800;
}
-inline int in_interrupt_context(void)
+inline bool in_interrupt_context(void)
{
return in_interrupt;
}
-int in_soft_interrupt_context(void)
+bool in_soft_interrupt_context(void)
{
/* group 16 is reserved for soft-irq */
return in_interrupt_context() && ec_int_group == 16;
diff --git a/include/task.h b/include/task.h
index 94b7a39908..fdfae9d5c6 100644
--- a/include/task.h
+++ b/include/task.h
@@ -83,7 +83,7 @@ void interrupt_enable(void);
/**
* Check if interrupts are enabled
*/
-int is_interrupt_enabled(void);
+bool is_interrupt_enabled(void);
/*
* Define irq_lock and irq_unlock that match the function signatures to Zephyr's
@@ -119,12 +119,12 @@ void irq_unlock(uint32_t key);
/**
* Return true if we are in interrupt context.
*/
-int in_interrupt_context(void);
+bool in_interrupt_context(void);
/**
* Return true if we are in software interrupt context.
*/
-int in_soft_interrupt_context(void);
+bool in_soft_interrupt_context(void);
/**
* Return current interrupt mask with disabling interrupt. Meaning is
diff --git a/zephyr/shim/src/tasks.c b/zephyr/shim/src/tasks.c
index 252fe5e66e..89e544c342 100644
--- a/zephyr/shim/src/tasks.c
+++ b/zephyr/shim/src/tasks.c
@@ -366,7 +366,7 @@ void task_enable_irq(int irq)
arch_irq_enable(irq);
}
-inline int in_interrupt_context(void)
+inline bool in_interrupt_context(void)
{
return k_is_in_isr();
}