1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-09 00:00:00 +01:00

uldaq : fix race condition between daq and read from buffer

This commit is contained in:
Manuel Pitz 2018-10-06 15:15:21 +02:00
parent e7d0af6b6b
commit 963fe79290

View file

@ -456,21 +456,20 @@ int uldaq_read(struct node *n, struct sample *smps[], unsigned cnt, unsigned *re
{
struct uldaq *u = (struct uldaq *) n->_vd;
/* Wait for data available condition triggered by event callback */
pthread_mutex_lock(&u->in.mutex);
pthread_cond_wait(&u->in.cv, &u->in.mutex);
if (u->in.status != SS_RUNNING)
return -1;
if (cnt != n->in.vectorize)
return -1;
//long long start_index = u->in.transfer_status.currentIndex - (n->in.vectorize-1) * u->in.channel_count;
/* Wait for data available condition triggered by event callback */
pthread_mutex_lock(&u->in.mutex);
long long current_index = u->in.transfer_status.currentIndex + u->in.channel_count;
long long start_index = u->buffer_pos;
if(start_index < 0){
start_index += u->in.buffer_len;
}
if (start_index + n->in.vectorize * u->in.channel_count > current_index)
pthread_cond_wait(&u->in.cv, &u->in.mutex);
#if 0
debug(2, "total count = %lld", u->in.transfer_status.currentTotalCount);