Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 37 additions & 27 deletions system/settings/settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ static int set_ip(FAR setting_t *setting, FAR struct in_addr *ip);
static int load(void);
static void save(void);
static void signotify(void);
static void dump_cache_locked(FAR bool *wrpend);
#ifdef CONFIG_SYSTEM_SETTINGS_CACHED_SAVES
static void dump_cache(union sigval ptr);
#endif

/****************************************************************************
* Private Data
Expand Down Expand Up @@ -623,12 +626,7 @@ static void save(void)
#ifdef CONFIG_SYSTEM_SETTINGS_CACHED_SAVES
timer_settime(g_settings.timerid, 0, &g_settings.trigger, NULL);
#else
union sigval value =
{
.sival_ptr = &g_settings.wrpend,
};

dump_cache(value);
dump_cache_locked(&g_settings.wrpend);
#endif
}

Expand Down Expand Up @@ -662,51 +660,63 @@ static void signotify(void)
}

/****************************************************************************
* Name: dump_cache
* Name: dump_cache_locked
*
* Description:
* Writes out the cached data to the appropriate storage
* Writes out the cached data to the appropriate storage. The caller
* must hold g_settings.mtx.
*
* Input Parameters:
* value - parameter passed if called from a timer signal
* wrpend - pending write flag to clear after dumping
*
* Returned Value:
* None
*
****************************************************************************/

static void dump_cache(union sigval ptr)
static void dump_cache_locked(FAR bool *wrpend)
{
int ret = OK;
FAR bool *wrpend = (bool *)ptr.sival_ptr;

int i;

ret = pthread_mutex_lock(&g_settings.mtx);
assert(ret >= 0);

for (i = 0; i < CONFIG_SYSTEM_SETTINGS_MAX_STORAGES; i++)
{
if ((g_settings.store[i].file[0] != '\0') &&
g_settings.store[i].save_fn)
{
ret = g_settings.store[i].save_fn(g_settings.store[i].file);
#if 0
if (ret < 0)
{
/* What to do? We can't return anything from a void function.
*
* MIGHT BE A FUTURE REVISIT NEEDED
*/
}
#endif
(void)g_settings.store[i].save_fn(g_settings.store[i].file);
}
}

*wrpend = false;
}

#ifdef CONFIG_SYSTEM_SETTINGS_CACHED_SAVES
/****************************************************************************
* Name: dump_cache
*
* Description:
* Writes out the cached data to the appropriate storage
*
* Input Parameters:
* value - parameter passed if called from a timer signal
*
* Returned Value:
* None
*
****************************************************************************/

static void dump_cache(union sigval ptr)
{
FAR bool *wrpend = (FAR bool *)ptr.sival_ptr;
int ret;

ret = pthread_mutex_lock(&g_settings.mtx);
assert(ret >= 0);

dump_cache_locked(wrpend);
pthread_mutex_unlock(&g_settings.mtx);
}
#endif

/****************************************************************************
* Name: sanity_check
Expand Down Expand Up @@ -762,9 +772,9 @@ void settings_init(void)
pthread_mutexattr_t attr;

pthread_mutexattr_init(&attr);
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
pthread_mutexattr_setprotocol(&attr, PTHREAD_PRIO_INHERIT);
pthread_mutex_init(&g_settings.mtx, &attr);
pthread_mutexattr_destroy(&attr);

memset(map, 0, sizeof(map));
memset(g_settings.store, 0, sizeof(g_settings.store));
Expand Down
Loading