sandbox: vm: add synchronisation using spinlocks

This commit is contained in:
2023-02-02 21:14:02 +00:00
parent d4449b8d87
commit 4237b6ca20
3 changed files with 28 additions and 2 deletions

View File

@@ -140,6 +140,9 @@ static unsigned int pointer_to_slot(vm_slab_t *slab, void *p)
void *vm_cache_alloc(vm_cache_t *cache, vm_flags_t flags)
{
unsigned long irq_flags;
spin_lock_irqsave(&cache->c_lock, &irq_flags);
vm_slab_t *slab = NULL;
if (!queue_empty(&cache->c_slabs_partial)) {
/* prefer using up partially-full slabs before taking a fresh one */
@@ -156,6 +159,7 @@ void *vm_cache_alloc(vm_cache_t *cache, vm_flags_t flags)
}
if (!slab) {
spin_unlock_irqrestore(&cache->c_lock, irq_flags);
return NULL;
}
@@ -167,7 +171,8 @@ void *vm_cache_alloc(vm_cache_t *cache, vm_flags_t flags)
} else {
queue_push_back(&cache->c_slabs_partial, &slab->s_list);
}
spin_unlock_irqrestore(&cache->c_lock, irq_flags);
return p;
}