Skip to content

Commit

Permalink
subsys/settings: Cleanup the initialisation of the subsys
Browse files Browse the repository at this point in the history
This commit removes redundant checks if the module
was already initialized.
The variable to mark the fact of initialization is
moved as a global module variable.
This allows creating more sophisticated unit tests
of the settings subsystem by giving a possibility to modify
the internal mark of the fact the system was initialized.

Signed-off-by: Radoslaw Koppel <[email protected]>
  • Loading branch information
rakons authored and carlescufi committed Jun 3, 2019
1 parent bd00108 commit b748a54
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
10 changes: 3 additions & 7 deletions subsys/settings/src/settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,15 @@ LOG_MODULE_REGISTER(settings, CONFIG_SETTINGS_LOG_LEVEL);

sys_slist_t settings_handlers;

static u8_t settings_cmd_inited;

static struct settings_handler *settings_handler_lookup(char *name);

void settings_store_init(void);

void settings_init(void)
{
if (!settings_cmd_inited) {
sys_slist_init(&settings_handlers);
settings_store_init();

settings_cmd_inited = 1U;
}
sys_slist_init(&settings_handlers);
settings_store_init();
}

int settings_register(struct settings_handler *handler)
Expand Down
9 changes: 6 additions & 3 deletions subsys/settings/src/settings_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
#include "settings/settings_file.h"
#include <zephyr.h>


bool settings_subsys_initialized;

void settings_init(void);

int settings_backend_init(void);
Expand Down Expand Up @@ -123,10 +126,10 @@ int settings_backend_init(void)

int settings_subsys_init(void)
{
static bool settings_initialized;

int err = 0;

if (settings_initialized) {
if (settings_subsys_initialized) {
return 0;
}

Expand All @@ -135,7 +138,7 @@ int settings_subsys_init(void)
err = settings_backend_init(); /* func rises kernel panic once error */

if (!err) {
settings_initialized = true;
settings_subsys_initialized = true;
}

return err;
Expand Down

0 comments on commit b748a54

Please sign in to comment.