diff options
Diffstat (limited to 'src/threadsafe_queue_fifo.h')
-rw-r--r-- | src/threadsafe_queue_fifo.h | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/src/threadsafe_queue_fifo.h b/src/threadsafe_queue_fifo.h index 30f6645..404e2f9 100644 --- a/src/threadsafe_queue_fifo.h +++ b/src/threadsafe_queue_fifo.h @@ -32,30 +32,36 @@ #include <queue> template <typename T> -class ThreadSafeQueueFIFO: public ThreadSafeQueue<T> { +class ThreadSafeQueueFIFO: ThreadSafeQueue<T> { public: ThreadSafeQueueFIFO() {} ~ThreadSafeQueueFIFO() {} void push(T t) { // Lock mutex - pthread_mutex_lock( &mutex ); + // pthread_mutex_lock( &mutex ); + mutex.lock(); queue.push(t); - pthread_mutex_unlock( &mutex ); + // pthread_mutex_unlock( &mutex ); + mutex.unlock(); // Unlock mutex - sem_post(&semaphore); + semaphore.post(); + //sem_post(&semaphore); } T pop() { - sem_wait(&semaphore); + semaphore.wait(); + // sem_wait(&semaphore); T t; // Lock mutex - pthread_mutex_lock( &mutex ); + // pthread_mutex_lock( &mutex ); + mutex.lock(); t = queue.front(); queue.pop(); - pthread_mutex_unlock( &mutex ); + // pthread_mutex_unlock( &mutex ); + mutex.unlock(); // Unlock mutex return t; @@ -65,9 +71,11 @@ public: int sz; // Lock mutex - pthread_mutex_lock( &mutex ); + // pthread_mutex_lock( &mutex ); + mutex.lock(); sz = queue.size(); - pthread_mutex_unlock( &mutex ); + // pthread_mutex_unlock( &mutex ); + mutex.unlock(); // Unlock mutex return sz; |