Skip to content

Commit

Permalink
add lock to settings
Browse files Browse the repository at this point in the history
  • Loading branch information
SciLor committed Apr 30, 2024
1 parent 5e441f3 commit 22cac78
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
2 changes: 2 additions & 0 deletions include/mutex_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ typedef enum
{
MUTEX_SETTINGS = 0,
MUTEX_SETTINGS_CN,
MUTEX_SETTINGS_SAVE,
MUTEX_SETTINGS_SAVE_OVL,
MUTEX_CLIENT_CTX,
MUTEX_SSE_CTX,
MUTEX_SSE_EVENT,
Expand Down
16 changes: 8 additions & 8 deletions src/settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -615,31 +615,30 @@ error_t settings_init(const char *cwd, const char *base_dir)

error_t settings_save()
{
mutex_lock(MUTEX_SETTINGS_SAVE);
error_t err = NO_ERROR;

err = settings_save_ovl(false);
if (err != NO_ERROR)
if (err == NO_ERROR)
{
return err;
}
err = settings_save_ovl(true);
if (err != NO_ERROR)
{
return err;
err = settings_save_ovl(true);
}
mutex_unlock(MUTEX_SETTINGS_SAVE);

return NO_ERROR;
return err;
}

error_t settings_save_ovl(bool overlay)
{
char_t *config_path = (!overlay ? config_file_path : config_overlay_file_path);

TRACE_INFO("Save settings to %s\r\n", config_path);
mutex_lock(MUTEX_SETTINGS_SAVE_OVL);
FsFile *file = fsOpenFile(config_path, FS_FILE_MODE_WRITE | FS_FILE_MODE_TRUNC);
if (file == NULL)
{
TRACE_ERROR("Failed to open config file for writing\r\n");
mutex_unlock(MUTEX_SETTINGS_SAVE_OVL);
return ERROR_DIRECTORY_NOT_FOUND;
}

Expand Down Expand Up @@ -714,6 +713,7 @@ error_t settings_save_ovl(bool overlay)
fsCloseFile(file);
Settings_Overlay[0].internal.config_changed = false;

mutex_unlock(MUTEX_SETTINGS_SAVE_OVL);
return NO_ERROR;
}

Expand Down

0 comments on commit 22cac78

Please sign in to comment.