kernel/mem_domain: Spinlockify

Simple locking requirements here mean we can just use a single
subsystem lock.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
This commit is contained in:
Andy Ross 2018-07-24 11:35:55 -07:00 committed by Anas Nashif
commit 04382b9a2a

View file

@ -10,7 +10,9 @@
#include <kernel_internal.h>
#include <misc/__assert.h>
#include <stdbool.h>
#include <spinlock.h>
static struct k_spinlock lock;
static u8_t max_partitions;
#if (defined(CONFIG_EXECUTE_XOR_WRITE) || \
@ -81,13 +83,13 @@ static inline bool sane_partition_domain(const struct k_mem_domain *domain,
void k_mem_domain_init(struct k_mem_domain *domain, u8_t num_parts,
struct k_mem_partition *parts[])
{
unsigned int key;
k_spinlock_key_t key;
__ASSERT(domain != NULL, "");
__ASSERT(num_parts == 0 || parts != NULL, "");
__ASSERT(num_parts <= max_partitions, "");
key = irq_lock();
key = k_spin_lock(&lock);
domain->num_partitions = 0;
(void)memset(domain->partitions, 0, sizeof(domain->partitions));
@ -113,17 +115,17 @@ void k_mem_domain_init(struct k_mem_domain *domain, u8_t num_parts,
sys_dlist_init(&domain->mem_domain_q);
irq_unlock(key);
k_spin_unlock(&lock, key);
}
void k_mem_domain_destroy(struct k_mem_domain *domain)
{
unsigned int key;
k_spinlock_key_t key;
sys_dnode_t *node, *next_node;
__ASSERT(domain != NULL, "");
key = irq_lock();
key = k_spin_lock(&lock);
/* Handle architecture-specific destroy
* only if it is the current thread.
@ -140,14 +142,14 @@ void k_mem_domain_destroy(struct k_mem_domain *domain)
thread->mem_domain_info.mem_domain = NULL;
}
irq_unlock(key);
k_spin_unlock(&lock, key);
}
void k_mem_domain_add_partition(struct k_mem_domain *domain,
struct k_mem_partition *part)
{
int p_idx;
unsigned int key;
k_spinlock_key_t key;
__ASSERT(domain != NULL, "");
__ASSERT(part != NULL, "");
@ -158,7 +160,7 @@ void k_mem_domain_add_partition(struct k_mem_domain *domain,
__ASSERT(sane_partition_domain(domain, part), "");
#endif
key = irq_lock();
key = k_spin_lock(&lock);
for (p_idx = 0; p_idx < max_partitions; p_idx++) {
/* A zero-sized partition denotes it's a free partition */
@ -176,19 +178,19 @@ void k_mem_domain_add_partition(struct k_mem_domain *domain,
domain->num_partitions++;
irq_unlock(key);
k_spin_unlock(&lock, key);
}
void k_mem_domain_remove_partition(struct k_mem_domain *domain,
struct k_mem_partition *part)
{
int p_idx;
unsigned int key;
k_spinlock_key_t key;
__ASSERT(domain != NULL, "");
__ASSERT(part != NULL, "");
key = irq_lock();
key = k_spin_lock(&lock);
/* find a partition that matches the given start and size */
for (p_idx = 0; p_idx < max_partitions; p_idx++) {
@ -213,19 +215,19 @@ void k_mem_domain_remove_partition(struct k_mem_domain *domain,
domain->num_partitions--;
irq_unlock(key);
k_spin_unlock(&lock, key);
}
void k_mem_domain_add_thread(struct k_mem_domain *domain, k_tid_t thread)
{
unsigned int key;
k_spinlock_key_t key;
__ASSERT(domain != NULL, "");
__ASSERT(thread != NULL, "");
__ASSERT(thread->mem_domain_info.mem_domain == NULL,
"mem domain unset");
key = irq_lock();
key = k_spin_lock(&lock);
sys_dlist_append(&domain->mem_domain_q,
&thread->mem_domain_info.mem_domain_q_node);
@ -235,17 +237,17 @@ void k_mem_domain_add_thread(struct k_mem_domain *domain, k_tid_t thread)
_arch_mem_domain_configure(thread);
}
irq_unlock(key);
k_spin_unlock(&lock, key);
}
void k_mem_domain_remove_thread(k_tid_t thread)
{
unsigned int key;
k_spinlock_key_t key;
__ASSERT(thread != NULL, "");
__ASSERT(thread->mem_domain_info.mem_domain != NULL, "mem domain set");
key = irq_lock();
key = k_spin_lock(&lock);
if (_current == thread) {
_arch_mem_domain_destroy(thread->mem_domain_info.mem_domain);
}
@ -253,7 +255,7 @@ void k_mem_domain_remove_thread(k_tid_t thread)
sys_dlist_remove(&thread->mem_domain_info.mem_domain_q_node);
thread->mem_domain_info.mem_domain = NULL;
irq_unlock(key);
k_spin_unlock(&lock, key);
}
static int init_mem_domain_module(struct device *arg)