aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Gustafsson <robg@student.chalmers.se>2017-10-23 10:25:38 +0200
committerRobert Gustafsson <robg@student.chalmers.se>2017-10-23 10:25:38 +0200
commit7a506e694ba0c6b69e8ef75c0aff6f7080970b3a (patch)
tree423582b0ea792853ee5e94a694775eea2fbeb883
parent495a229b4bea6c2dcc918ddecf2207e42bbc5346 (diff)
downloadmidbro-7a506e694ba0c6b69e8ef75c0aff6f7080970b3a.tar.gz
midbro-7a506e694ba0c6b69e8ef75c0aff6f7080970b3a.tar.bz2
Better handling of semaphores
-rw-r--r--broccoli/src/fifoqueue.c13
1 files changed, 2 insertions, 11 deletions
diff --git a/broccoli/src/fifoqueue.c b/broccoli/src/fifoqueue.c
index f3d9272..3911eb7 100644
--- a/broccoli/src/fifoqueue.c
+++ b/broccoli/src/fifoqueue.c
@@ -65,7 +65,6 @@ add_to_queue(Fifo_q * q, Sensor_t * sensor)
new_elem->sensor = sensor;
if(is_empty(q)){
q->head = new_elem;
- sem_post(&q->bufferEmptyBlock);
}else
q->tail->next = new_elem;
q->tail = new_elem;
@@ -74,6 +73,7 @@ add_to_queue(Fifo_q * q, Sensor_t * sensor)
if(q->currentSize > q->largestBufferSize)
q->largestBufferSize = q->currentSize;
sem_post(&q->lock);
+ sem_post(&q->bufferEmptyBlock);
return 1;
}
@@ -81,12 +81,7 @@ add_to_queue(Fifo_q * q, Sensor_t * sensor)
pop_from_queue(Fifo_q * q)
{
int semStat;
- if(is_empty(q)){
- #ifdef DEBUG
- printf("Waiting for sensor data\n");
- #endif
- sem_wait(&q->bufferEmptyBlock);
- }
+ sem_wait(&q->bufferEmptyBlock);
sem_wait(&q->lock);
Queue_t * head = q->head;
Sensor_t * sensor = head->sensor;
@@ -94,10 +89,6 @@ pop_from_queue(Fifo_q * q)
if(q->currentSize == 1){
q->head = NULL;
q->tail = NULL;
- /* Read current semaphore value */
- sem_getvalue(&q->bufferEmptyBlock, &semStat);
- if(semStat == 1) /* Mark buffer as empty if last elem */
- sem_wait(&q->bufferEmptyBlock);
}else{
q->head = head->next;
}