Reorganised codec_pushFrame and codec_popFrame functions for true non-blocking behaviour
This commit is contained in:
parent
9d021b7557
commit
5ee3a2e9f0
|
|
@ -172,22 +172,16 @@ bool codec_popFrame(uint8_t *frame, const bool blocking)
|
||||||
if(running == false) return false;
|
if(running == false) return false;
|
||||||
|
|
||||||
uint64_t element;
|
uint64_t element;
|
||||||
pthread_mutex_lock(&mutex);
|
|
||||||
|
|
||||||
if(numElements == 0)
|
// No data available and non-blocking call: just return false.
|
||||||
|
if((numElements == 0) && (blocking == false))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// Blocking call: wait until some data is pushed
|
||||||
|
pthread_mutex_lock(&mutex);
|
||||||
|
while(numElements == 0)
|
||||||
{
|
{
|
||||||
if(blocking)
|
pthread_cond_wait(¬_empty, &mutex);
|
||||||
{
|
|
||||||
while(numElements == 0)
|
|
||||||
{
|
|
||||||
pthread_cond_wait(¬_empty, &mutex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
pthread_mutex_unlock(&mutex);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
element = dataBuffer[readPos];
|
element = dataBuffer[readPos];
|
||||||
|
|
@ -211,16 +205,13 @@ bool codec_pushFrame(const uint8_t *frame, const bool blocking)
|
||||||
uint64_t element;
|
uint64_t element;
|
||||||
memcpy(&element, frame, 8);
|
memcpy(&element, frame, 8);
|
||||||
|
|
||||||
pthread_mutex_lock(&mutex);
|
|
||||||
|
|
||||||
|
// No space available and non-blocking call: return
|
||||||
if((numElements >= BUF_SIZE) && (blocking == false))
|
if((numElements >= BUF_SIZE) && (blocking == false))
|
||||||
{
|
|
||||||
// No space available and non-blocking call: unlock mutex and return
|
|
||||||
pthread_mutex_unlock(&mutex);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
// The call is blocking: wait until there is some free space
|
// Blocking call: wait until there is some free space
|
||||||
|
pthread_mutex_lock(&mutex);
|
||||||
while(numElements >= BUF_SIZE)
|
while(numElements >= BUF_SIZE)
|
||||||
{
|
{
|
||||||
pthread_cond_wait(¬_full, &mutex);
|
pthread_cond_wait(¬_full, &mutex);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue