diff --git a/drivers/retained_mem/Kconfig b/drivers/retained_mem/Kconfig index 476a82debf..8f134f9456 100644 --- a/drivers/retained_mem/Kconfig +++ b/drivers/retained_mem/Kconfig @@ -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 diff --git a/subsys/retention/Kconfig b/subsys/retention/Kconfig index 846661bdff..1081e236f0 100644 --- a/subsys/retention/Kconfig +++ b/subsys/retention/Kconfig @@ -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 diff --git a/subsys/retention/retention.c b/subsys/retention/retention.c index b1bda42c78..db5b8d45b6 100644 --- a/subsys/retention/retention.c +++ b/subsys/retention/retention.c @@ -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