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>
This commit is contained in:
parent
dd0715c770
commit
3b4b7c3a37
2 changed files with 4 additions and 2 deletions
|
@ -4841,6 +4841,7 @@ extern int k_mem_slab_init(struct k_mem_slab *slab, void *buffer,
|
|||
* 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
|
||||
*
|
||||
|
|
|
@ -121,7 +121,8 @@ int k_mem_slab_alloc(struct k_mem_slab *slab, void **mem, k_timeout_t timeout)
|
|||
#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 @@ void k_mem_slab_free(struct k_mem_slab *slab, void **mem)
|
|||
{
|
||||
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) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue