param & param_shmem: enable locking

We need to protect access to the param_values array. This is dynamically
allocated and resized (utarray_reserve() calls realloc). If some thread
was iterating the array while another was resizing the array, the first one
would iterate on a freed array, thus accessing invalid memory.

On NuttX this could lead to hardfaults in rare conditions.

Unfortunately we need to initialize the semaphore on startup, by calling
sem_init(). This adds a param_init() method called by every board/config
that uses the params (at least I think I've found all of them)
This commit is contained in:
Beat Küng
2017-02-17 11:27:08 +01:00
committed by Lorenz Meier
parent fa3a6b890c
commit df8f0da70c
22 changed files with 106 additions and 23 deletions
@@ -46,7 +46,7 @@
#include <signal.h>
#include <errno.h>
#include <unistd.h>
#include "systemlib/param/param.h"
#include <systemlib/param/param.h>
#include "hrt_work.h"
#include <drivers/drv_hrt.h>
#include "px4_time.h"
@@ -76,6 +76,7 @@ void init_once()
work_queues_init();
hrt_work_queue_init();
hrt_init();
param_init();
#ifdef CONFIG_SHMEM
PX4_DEBUG("Syncing params to shared memory\n");
@@ -48,7 +48,7 @@
#include <errno.h>
#include <unistd.h>
#include <semaphore.h>
#include "systemlib/param/param.h"
#include <systemlib/param/param.h>
#include "hrt_work.h"
#include "px4_log.h"
@@ -106,6 +106,7 @@ void init_once(void)
work_queues_init();
hrt_work_queue_init();
hrt_init();
param_init();
/* Shared memory param sync*/
init_params();