Fixed problem causing a failure to obtain the shared memory lock on the AppsProc.

This commit is contained in:
jwilson
2016-02-19 16:59:49 +01:00
committed by Julian Oes
parent 4adfea7fa9
commit 75fad09263
6 changed files with 25 additions and 76 deletions
+10 -8
View File
@@ -59,7 +59,7 @@ unsigned char *map_base, *virt_addr;
struct shmem_info *shmem_info_p;
static void *map_memory(off_t target);
int get_shmem_lock(void);
int get_shmem_lock(const char *caller_file_name, int caller_line_number);
void release_shmem_lock(void);
void init_shared_memory(void);
void copy_params_to_shmem(struct param_info_s *);
@@ -94,17 +94,19 @@ static void *map_memory(off_t target)
exit(1);
}
PX4_DEBUG("Initializing map memory: mem_fd: %d, 0x%X", mem_fd, map_base + (target & MAP_MASK) + LOCK_SIZE);
return (map_base + (target & MAP_MASK) + LOCK_SIZE);
}
int get_shmem_lock(void)
int get_shmem_lock(const char *caller_file_name, int caller_line_number)
{
int i = 0;
/*ioctl calls cmpxchg*/
while (ioctl(mem_fd, LOCK_MEM) != 0) {
PX4_INFO("Could not get lock, spinning\n");
PX4_INFO("Could not get lock, file name: %s, line number: %d\n", caller_file_name, caller_line_number);
usleep(100000); //sleep for 100 msec
i++;
@@ -122,7 +124,7 @@ int get_shmem_lock(void)
void release_shmem_lock(void)
{
*(virt_addr - LOCK_SIZE) = 1;
ioctl(mem_fd, UNLOCK_MEM);
}
void init_shared_memory(void)
@@ -139,7 +141,7 @@ void copy_params_to_shmem(struct param_info_s *param_info_base)
param_t param;
unsigned int i;
if (get_shmem_lock() != 0) {
if (get_shmem_lock(__FILE__, __LINE__) != 0) {
PX4_ERR("Could not get shmem lock\n");
return;
}
@@ -188,7 +190,7 @@ void update_to_shmem(param_t param, union param_value_u value)
{
unsigned int byte_changed, bit_changed;
if (get_shmem_lock() != 0) {
if (get_shmem_lock(__FILE__, __LINE__) != 0) {
fprintf(stderr, "Could not get shmem lock\n");
return;
}
@@ -222,7 +224,7 @@ static void update_index_from_shmem(void)
{
unsigned int i;
if (get_shmem_lock() != 0) {
if (get_shmem_lock(__FILE__, __LINE__) != 0) {
fprintf(stderr, "Could not get shmem lock\n");
return;
}
@@ -240,7 +242,7 @@ static void update_value_from_shmem(param_t param, union param_value_u *value)
{
unsigned int byte_changed, bit_changed;
if (get_shmem_lock() != 0) {
if (get_shmem_lock(__FILE__, __LINE__) != 0) {
fprintf(stderr, "Could not get shmem lock\n");
return;
}
-6
View File
@@ -220,12 +220,6 @@ int dspal_entry(int argc, char *argv[])
process_commands(apps, get_commands());
sleep(1); // give time for all commands to execute before starting external function
// TODO-JYW: TESTING-TESTING:
int default_mav_type = vehicle_status_s::VEHICLE_TYPE_QUADROTOR;
param_set(param_find("MAV_TYPE"), &default_mav_type);
PX4_INFO("setting default mav_type: %d", default_mav_type);
// TODO-JYW: TESTING-TESTING:
if (qurt_external_hook) {
qurt_external_hook();
}
+13 -8
View File
@@ -51,7 +51,7 @@ int mem_fd;
unsigned char *map_base, *virt_addr;
struct shmem_info *shmem_info_p;
static void *map_memory(off_t target);
int get_shmem_lock(void);
int get_shmem_lock(const char *caller_file_name, int caller_line_number);
void release_shmem_lock(void);
void init_shared_memory(void);
void copy_params_to_shmem(struct param_info_s *);
@@ -74,20 +74,25 @@ static void *map_memory(off_t target)
}
int get_shmem_lock(void)
int get_shmem_lock(const char *caller_file_name, int caller_line_number)
{
unsigned char *lock = (unsigned char *)(MAP_ADDRESS + LOCK_OFFSET);
unsigned int i = 0;
while (!atomic_compare_and_set(lock, 1, 0)) {
PX4_INFO("Could not get lock. spinning\n");
PX4_INFO("Could not get lock, file name: %s, line number: %d.\n",
caller_file_name, caller_line_number);
i++;
usleep(1000);
if (i > 100) { break; }
}
if (i > 100) { return -1; }
if (i > 100) {
return -1;
} else {
PX4_DEBUG("Lock acquired, file name: %s, line number: %d\n", caller_file_name, caller_line_number);
}
return 0; //got the lock
@@ -116,7 +121,7 @@ void copy_params_to_shmem(struct param_info_s *param_info_base)
param_t param;
unsigned int i;
if (get_shmem_lock() != 0) {
if (get_shmem_lock(__FILE__, __LINE__) != 0) {
PX4_INFO("Could not get shmem lock\n");
return;
}
@@ -163,7 +168,7 @@ void update_to_shmem(param_t param, union param_value_u value)
return;
}
if (get_shmem_lock() != 0) {
if (get_shmem_lock(__FILE__, __LINE__) != 0) {
PX4_ERR("Could not get shmem lock\n");
return;
}
@@ -198,7 +203,7 @@ static void update_index_from_shmem(void)
{
unsigned int i;
if (get_shmem_lock() != 0) {
if (get_shmem_lock(__FILE__, __LINE__) != 0) {
PX4_ERR("Could not get shmem lock\n");
return;
}
@@ -217,7 +222,7 @@ static void update_value_from_shmem(param_t param, union param_value_u *value)
{
unsigned int byte_changed, bit_changed;
if (get_shmem_lock() != 0) {
if (get_shmem_lock(__FILE__, __LINE__) != 0) {
PX4_ERR("Could not get shmem lock\n");
return;
}