kernel: mem_slab: Optimize mem_slab_free
Changed algorithm of checking for pending thread in mem_slab. Check for pending thread now is done only if there is no memory left. Signed-off-by: Kamil Lazowski <Kamil.Lazowski@nordicsemi.no>
This commit is contained in:
parent
a5a3798c6c
commit
303fca9f2a
1 changed files with 13 additions and 10 deletions
|
@ -143,16 +143,19 @@ int k_mem_slab_alloc(struct k_mem_slab *slab, void **mem, k_timeout_t timeout)
|
|||
void k_mem_slab_free(struct k_mem_slab *slab, void **mem)
|
||||
{
|
||||
k_spinlock_key_t key = k_spin_lock(&lock);
|
||||
|
||||
if (slab->free_list == NULL) {
|
||||
struct k_thread *pending_thread = z_unpend_first_thread(&slab->wait_q);
|
||||
|
||||
if (pending_thread != NULL) {
|
||||
z_thread_return_value_set_with_data(pending_thread, 0, *mem);
|
||||
z_ready_thread(pending_thread);
|
||||
z_reschedule(&lock, key);
|
||||
} else {
|
||||
**(char ***)mem = slab->free_list;
|
||||
slab->free_list = *(char **)mem;
|
||||
return;
|
||||
}
|
||||
}
|
||||
**(char ***) mem = slab->free_list;
|
||||
slab->free_list = *(char **) mem;
|
||||
slab->num_used--;
|
||||
k_spin_unlock(&lock, key);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue