From 3457fcb48baa8a5c547697845321e48970ccda75 Mon Sep 17 00:00:00 2001 From: "Gustavo J. A. M. Carneiro" Date: Thu, 4 Oct 2007 11:24:05 +0100 Subject: [PATCH] Fix race condition in mobility-visualizer-view; reduce refresh rate to 30fps. --- utils/mobility-visualizer-view.cc | 48 +++++++++++++------------------ utils/mobility-visualizer.h | 2 +- 2 files changed, 21 insertions(+), 29 deletions(-) diff --git a/utils/mobility-visualizer-view.cc b/utils/mobility-visualizer-view.cc index 18bc08ce5..c1370856b 100644 --- a/utils/mobility-visualizer-view.cc +++ b/utils/mobility-visualizer-view.cc @@ -104,48 +104,40 @@ void view_update (ViewUpdateData *updateData) void view_update_process (ViewUpdateData *updateData) { - if (firstTime) + for (std::vector::const_iterator update + = updateData->updateList.begin (); + update != updateData->updateList.end (); + update++) { - firstTime = FALSE; - g_get_current_time (&initialTime); - - for (std::vector::const_iterator update - = updateData->updateList.begin (); - update != updateData->updateList.end (); - update++) + if (g_nodes.find (update->node) == g_nodes.end ()) { g_nodes[update->node].create (); - g_nodes[update->node].update (update->x, update->y, update->vx, update->vy); } - delete updateData; - } - else - { - for (std::vector::const_iterator update - = updateData->updateList.begin (); - update != updateData->updateList.end (); - update++) - { - g_nodes[update->node].update (update->x, update->y, update->vx, update->vy); - } - delete updateData; - - g_static_mutex_lock (&g_lookaheadTimeMux); - g_lookaheadTime = get_current_time () + LOOKAHEAD_SECONDS; - g_static_mutex_unlock (&g_lookaheadTimeMux); + g_nodes[update->node].update (update->x, update->y, update->vx, update->vy); } + delete updateData; } gboolean view_update_consumer () { + if (firstTime) + { + firstTime = FALSE; + g_get_current_time (&initialTime); + } + + double now = get_current_time (); + g_static_mutex_lock (&g_lookaheadTimeMux); + g_lookaheadTime = now + LOOKAHEAD_SECONDS; + g_static_mutex_unlock (&g_lookaheadTimeMux); + if (!g_nextData) g_nextData = (ViewUpdateData *) g_async_queue_try_pop (queue); if (!g_nextData) return TRUE; - double time = get_current_time (); - if (g_nextData->time > time) + if (g_nextData->time > now) return TRUE; do @@ -153,7 +145,7 @@ gboolean view_update_consumer () view_update_process (g_nextData); g_nextData = (ViewUpdateData *) g_async_queue_try_pop (queue); } - while (g_nextData && g_nextData->time <= time); + while (g_nextData && g_nextData->time <= now); return TRUE; } diff --git a/utils/mobility-visualizer.h b/utils/mobility-visualizer.h index 1e1719fcc..634847c3c 100644 --- a/utils/mobility-visualizer.h +++ b/utils/mobility-visualizer.h @@ -20,4 +20,4 @@ struct ViewUpdateData void view_update (ViewUpdateData *updateData); -#define SAMPLE_INTERVAL (1.0/100) // due to some race condition, this is the only value that works +#define SAMPLE_INTERVAL (1.0/30)