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)
|
void k_mem_slab_free(struct k_mem_slab *slab, void **mem)
|
||||||
{
|
{
|
||||||
k_spinlock_key_t key = k_spin_lock(&lock);
|
k_spinlock_key_t key = k_spin_lock(&lock);
|
||||||
struct k_thread *pending_thread = z_unpend_first_thread(&slab->wait_q);
|
|
||||||
|
|
||||||
if (pending_thread != NULL) {
|
if (slab->free_list == NULL) {
|
||||||
z_thread_return_value_set_with_data(pending_thread, 0, *mem);
|
struct k_thread *pending_thread = z_unpend_first_thread(&slab->wait_q);
|
||||||
z_ready_thread(pending_thread);
|
|
||||||
z_reschedule(&lock, key);
|
if (pending_thread != NULL) {
|
||||||
} else {
|
z_thread_return_value_set_with_data(pending_thread, 0, *mem);
|
||||||
**(char ***)mem = slab->free_list;
|
z_ready_thread(pending_thread);
|
||||||
slab->free_list = *(char **)mem;
|
z_reschedule(&lock, key);
|
||||||
slab->num_used--;
|
return;
|
||||||
k_spin_unlock(&lock, key);
|
}
|
||||||
}
|
}
|
||||||
|
**(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