kernel: mem_slab: Add support to no multithreading Mem_slab supports allocation with timeout which blocks the context if no slab is available. Updated to treat every timeout as K_NO_WAIT when multithreading is disabled. Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
diff --git a/include/kernel.h b/include/kernel.h index 638d65d..7edb398 100644 --- a/include/kernel.h +++ b/include/kernel.h
@@ -4841,6 +4841,7 @@ * This routine allocates a memory block from a memory slab. * * @note @a timeout must be set to K_NO_WAIT if called from ISR. + * @note When CONFIG_MULTITHREADING=n any @timeout is treated as K_NO_WAIT. * * @funcprops \isr_ok *
diff --git a/kernel/mem_slab.c b/kernel/mem_slab.c index 30fa141..883a97c 100644 --- a/kernel/mem_slab.c +++ b/kernel/mem_slab.c
@@ -121,7 +121,8 @@ #endif result = 0; - } else if (K_TIMEOUT_EQ(timeout, K_NO_WAIT)) { + } else if (K_TIMEOUT_EQ(timeout, K_NO_WAIT) || + !IS_ENABLED(CONFIG_MULTITHREADING)) { /* don't wait for a free block to become available */ *mem = NULL; result = -ENOMEM; @@ -143,7 +144,7 @@ { k_spinlock_key_t key = k_spin_lock(&slab->lock); - if (slab->free_list == NULL) { + if (slab->free_list == NULL && IS_ENABLED(CONFIG_MULTITHREADING)) { struct k_thread *pending_thread = z_unpend_first_thread(&slab->wait_q); if (pending_thread != NULL) {