This is an automated email from the ASF dual-hosted git repository.
jerzy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git
The following commit(s) were added to refs/heads/master by this push:
new c21a93ba7 kernel/os: Reduce mutex and sem code for bootloader
c21a93ba7 is described below
commit c21a93ba70bb3b7ed2bf23beac466cd153d9df87
Author: Jerzy Kasenberg <[email protected]>
AuthorDate: Fri Mar 21 10:23:28 2025 +0100
kernel/os: Reduce mutex and sem code for bootloader
os_mutex os_sem can be build in bootloader code (OS_SCHEDULING == 0)
Mutex code checks at runtime value of g_os_started.
For bootloader this will never be set to 1 but mutex code
will force inclusion of task related code and data that
will never be used.
This adds simple conditions at the beginning of mutex sem functions,
condition is always false for bootloader build and compiler
will remove all unreachable code.
Signed-off-by: Jerzy Kasenberg <[email protected]>
---
kernel/os/src/os_mutex.c | 12 ++++++++++++
kernel/os/src/os_sem.c | 12 ++++++++++++
2 files changed, 24 insertions(+)
diff --git a/kernel/os/src/os_mutex.c b/kernel/os/src/os_mutex.c
index f15725f53..c9b9e8b13 100644
--- a/kernel/os/src/os_mutex.c
+++ b/kernel/os/src/os_mutex.c
@@ -29,6 +29,10 @@ os_mutex_init(struct os_mutex *mu)
{
os_error_t ret;
+ if (!MYNEWT_VAL(OS_SCHEDULING)) {
+ return OS_OK;
+ }
+
if (!mu) {
ret = OS_INVALID_PARM;
goto done;
@@ -58,6 +62,10 @@ os_mutex_release(struct os_mutex *mu)
struct os_task *rdy;
os_error_t ret;
+ if (!MYNEWT_VAL(OS_SCHEDULING)) {
+ return OS_NOT_STARTED;
+ }
+
os_trace_api_u32(OS_TRACE_ID_MUTEX_RELEASE, (uintptr_t)mu);
/* Check if OS is started */
@@ -145,6 +153,10 @@ os_mutex_pend(struct os_mutex *mu, os_time_t timeout)
struct os_task *entry;
struct os_task *last;
+ if (!MYNEWT_VAL(OS_SCHEDULING)) {
+ return OS_NOT_STARTED;
+ }
+
os_trace_api_u32x2(OS_TRACE_ID_MUTEX_PEND, (uintptr_t)mu,
(uint32_t)timeout);
/* OS must be started when calling this function */
diff --git a/kernel/os/src/os_sem.c b/kernel/os/src/os_sem.c
index eb95ec853..e0f6ee829 100644
--- a/kernel/os/src/os_sem.c
+++ b/kernel/os/src/os_sem.c
@@ -35,6 +35,10 @@ os_sem_init(struct os_sem *sem, uint16_t tokens)
{
os_error_t ret;
+ if (!MYNEWT_VAL(OS_SCHEDULING)) {
+ return OS_OK;
+ }
+
os_trace_api_u32x2(OS_TRACE_ID_SEM_INIT, (uint32_t)(uintptr_t)sem,
(uint32_t)tokens);
if (!sem) {
@@ -61,6 +65,10 @@ os_sem_release(struct os_sem *sem)
struct os_task *rdy;
os_error_t ret;
+ if (!MYNEWT_VAL(OS_SCHEDULING)) {
+ return OS_NOT_STARTED;
+ }
+
os_trace_api_u32(OS_TRACE_ID_SEM_RELEASE, (uint32_t)(uintptr_t)sem);
/* OS must be started to release semaphores */
@@ -129,6 +137,10 @@ os_sem_pend(struct os_sem *sem, os_time_t timeout)
struct os_task *last;
os_error_t ret;
+ if (!MYNEWT_VAL(OS_SCHEDULING)) {
+ return OS_NOT_STARTED;
+ }
+
os_trace_api_u32x2(OS_TRACE_ID_SEM_PEND, (uint32_t)(uintptr_t)sem,
(uint32_t)timeout);
/* Check if OS is started */