From db1c9eaa97233dc9afcfeea288a35aed5db38be2 Mon Sep 17 00:00:00 2001 From: Manuel Pitz Date: Wed, 20 Feb 2019 18:59:23 +0000 Subject: [PATCH] fix race condition between usb buffer and data transfer buffer --- etc/uldaq.conf | 2 +- lib/nodes/uldaq.c | 16 ++++------------ 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/etc/uldaq.conf b/etc/uldaq.conf index cc72d2946..06ead6346 100644 --- a/etc/uldaq.conf +++ b/etc/uldaq.conf @@ -37,7 +37,7 @@ nodes = { }, out = { vectorize = 100 - address = "192.168.104.10:13000" + address = "10.100.1.125:13000" } } } diff --git a/lib/nodes/uldaq.c b/lib/nodes/uldaq.c index 67b046f30..79c0ba2b6 100644 --- a/lib/nodes/uldaq.c +++ b/lib/nodes/uldaq.c @@ -598,26 +598,18 @@ int uldaq_read(struct node *n, struct sample *smps[], unsigned cnt, unsigned *re { struct uldaq *u = (struct uldaq *) n->_vd; - size_t buffer_incr = n->in.vectorize * u->in.channel_count; - pthread_mutex_lock(&u->in.mutex); - /* Wait for data available condition triggered by event callback */ - if (u->in.buffer_pos + buffer_incr < u->in.transfer_status.currentIndex) - pthread_cond_wait(&u->in.cv, &u->in.mutex); - -#if 1 - debug(2, "Total count = %lld", u->in.transfer_status.currentTotalCount); - debug(2, "Index = %lld", u->in.transfer_status.currentIndex); - debug(2, "Scan count = %lld", u->in.transfer_status.currentScanCount); - debug(2, "Buffer pos = %zu", u->in.buffer_pos); -#endif if (u->in.status != SS_RUNNING) return -1; long long start_index = u->in.buffer_pos; + /* Wait for data available condition triggered by event callback */ + if (start_index + n->in.vectorize * u->in.channel_count > u->in.transfer_status.currentScanCount) + pthread_cond_wait(&u->in.cv, &u->in.mutex); + for (int j = 0; j < cnt; j++) { struct sample *smp = smps[j];