diff options
author | Jean Cyr <jcyr@dillobits.com> | 2014-05-13 20:24:19 -0400 |
---|---|---|
committer | Jean Cyr <jcyr@dillobits.com> | 2014-05-13 20:24:19 -0400 |
commit | cd9a72e391948fbf620c8cb129020ae7ecc9cab3 (patch) | |
tree | 90a40d0cc4cfbeb9bde118553da559af732c234a /src | |
parent | 8d3fed09443faa6a3c79b68b7800ed3472877a1c (diff) | |
download | px4-firmware-cd9a72e391948fbf620c8cb129020ae7ecc9cab3.tar.gz px4-firmware-cd9a72e391948fbf620c8cb129020ae7ecc9cab3.tar.bz2 px4-firmware-cd9a72e391948fbf620c8cb129020ae7ecc9cab3.zip |
Free data manager work items the same way they were allocated
Since data manager work items are allocated in groups of 8, they need to
be freed the same way should the manager need to stop.
Diffstat (limited to 'src')
-rw-r--r-- | src/modules/dataman/dataman.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/modules/dataman/dataman.c b/src/modules/dataman/dataman.c index cbd9b2d7c..16703899d 100644 --- a/src/modules/dataman/dataman.c +++ b/src/modules/dataman/dataman.c @@ -75,7 +75,8 @@ typedef enum { typedef struct { sq_entry_t link; /**< list linkage */ sem_t wait_sem; - dm_function_t func; + unsigned char first; + unsigned char func; ssize_t result; union { struct { @@ -183,9 +184,12 @@ create_work_item(void) if (item == NULL) { item = (work_q_item_t *)malloc(k_work_item_allocation_chunk_size * sizeof(work_q_item_t)); if (item) { + item->first = 1; lock_queue(&g_free_q); - for (int i = 1; i < k_work_item_allocation_chunk_size; i++) + for (int i = 1; i < k_work_item_allocation_chunk_size; i++) { + (item + i)->first = 0; sq_addfirst(&(item + i)->link, &(g_free_q.q)); + } /* Update the queue size and potentially the maximum queue size */ g_free_q.size += k_work_item_allocation_chunk_size - 1; if (g_free_q.size > g_free_q.max_size) @@ -730,8 +734,8 @@ task_main(int argc, char *argv[]) for (;;) { if ((work = (work_q_item_t *)sq_remfirst(&(g_free_q.q))) == NULL) break; - - free(work); + if (work->first) + free(work); } destroy_q(&g_work_q); |