retention: Add optional mutex disablement

Adds an optional Kconfig to disable use of mutexes in the
retention subsystem.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
This commit is contained in:
Jamie McCrae 2023-04-06 12:13:43 +01:00 committed by Carles Cufí
parent 0bf39f4a94
commit 4cdfa7bdd5
3 changed files with 15 additions and 6 deletions

View file

@ -16,7 +16,7 @@ config RETAINED_MEM_INIT_PRIORITY
Retained memory devices initialization priority,
config RETAINED_MEM_MUTEXES
int "Retained memory mutex support"
bool "Retained memory mutex support"
default y
depends on MULTITHREADING
help

View file

@ -19,6 +19,15 @@ config RETENTION_INIT_PRIORITY
Retention device initialization priority (must be higher than init
priorities for retained memory drivers.
config RETENTION_MUTEXES
bool "Retention mutex support"
default y
depends on MULTITHREADING
help
Use mutexes to prevent issues with concurrent retention device
access. Should only be disabled whereby retained memory access is
required in an ISR or for special use cases.
config RETENTION_BUFFER_SIZE
int "Retention stack buffer sizes"
default 16

View file

@ -31,7 +31,7 @@ enum {
struct retention_data {
bool header_written;
#ifdef CONFIG_MULTITHREADING
#ifdef CONFIG_RETENTION_MUTEXES
struct k_mutex lock;
#endif
};
@ -48,7 +48,7 @@ struct retention_config {
static inline void retention_lock_take(const struct device *dev)
{
#ifdef CONFIG_MULTITHREADING
#ifdef CONFIG_RETENTION_MUTEXES
struct retention_data *data = dev->data;
k_mutex_lock(&data->lock, K_FOREVER);
@ -59,7 +59,7 @@ static inline void retention_lock_take(const struct device *dev)
static inline void retention_lock_release(const struct device *dev)
{
#ifdef CONFIG_MULTITHREADING
#ifdef CONFIG_RETENTION_MUTEXES
struct retention_data *data = dev->data;
k_mutex_unlock(&data->lock);
@ -112,7 +112,7 @@ finish:
static int retention_init(const struct device *dev)
{
const struct retention_config *config = dev->config;
#ifdef CONFIG_MULTITHREADING
#ifdef CONFIG_RETENTION_MUTEXES
struct retention_data *data = dev->data;
#endif
ssize_t area_size;
@ -139,7 +139,7 @@ static int retention_init(const struct device *dev)
return -EINVAL;
}
#ifdef CONFIG_MULTITHREADING
#ifdef CONFIG_RETENTION_MUTEXES
k_mutex_init(&data->lock);
#endif