summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordeva <deva>2005-10-08 16:07:50 +0000
committerdeva <deva>2005-10-08 16:07:50 +0000
commit48775e1ce9eb0dd53908110454d068a8b16a66ec (patch)
treeba200df1f9ef178f2e17d54caee3d8b40db0fbe6
parentb6a85d646c94f8b1efc51c4a50a644fc902c9521 (diff)
*** empty log message ***
-rw-r--r--src/threadsafe_queue_fifo.cc38
-rw-r--r--src/threadsafe_queue_fifo.h52
2 files changed, 21 insertions, 69 deletions
diff --git a/src/threadsafe_queue_fifo.cc b/src/threadsafe_queue_fifo.cc
index 633cb58..50c1067 100644
--- a/src/threadsafe_queue_fifo.cc
+++ b/src/threadsafe_queue_fifo.cc
@@ -26,10 +26,9 @@
*/
#include "config.h"
#include "threadsafe_queue_fifo.h"
-/*
+
template <typename T>
ThreadSafeQueueFIFO<T>::ThreadSafeQueueFIFO()
- // : ThreadSafeQueue<T>()
{
}
@@ -41,29 +40,25 @@ ThreadSafeQueueFIFO<T>::~ThreadSafeQueueFIFO()
template <typename T>
void ThreadSafeQueueFIFO<T>::push(T t)
{
- // Lock mutex
- pthread_mutex_lock( &mutex );
+ mutex.lock();
queue.push(t);
- pthread_mutex_unlock( &mutex );
- // Unlock mutex
-
- sem_post(&semaphore);
+ mutex.unlock();
+
+ semaphore.post();
}
template <typename T>
T ThreadSafeQueueFIFO<T>::pop()
{
- sem_wait(&semaphore);
-
+ semaphore.wait();
+
T t;
-
- // Lock mutex
- pthread_mutex_lock( &mutex );
+
+ mutex.lock();
t = queue.front();
queue.pop();
- pthread_mutex_unlock( &mutex );
- // Unlock mutex
-
+ mutex.unlock();
+
return t;
}
@@ -71,13 +66,10 @@ template <typename T>
int ThreadSafeQueueFIFO<T>::size()
{
int sz;
-
- // Lock mutex
- pthread_mutex_lock( &mutex );
+
+ mutex.lock();
sz = queue.size();
- pthread_mutex_unlock( &mutex );
- // Unlock mutex
-
+ mutex.unlock();
+
return sz;
}
-*/
diff --git a/src/threadsafe_queue_fifo.h b/src/threadsafe_queue_fifo.h
index 404e2f9..9baf82e 100644
--- a/src/threadsafe_queue_fifo.h
+++ b/src/threadsafe_queue_fifo.h
@@ -32,54 +32,14 @@
#include <queue>
template <typename T>
-class ThreadSafeQueueFIFO: ThreadSafeQueue<T> {
+class ThreadSafeQueueFIFO: public ThreadSafeQueue<T> {
public:
- ThreadSafeQueueFIFO() {}
- ~ThreadSafeQueueFIFO() {}
+ ThreadSafeQueueFIFO();
+ ~ThreadSafeQueueFIFO();
- void push(T t) {
- // Lock mutex
- // pthread_mutex_lock( &mutex );
- mutex.lock();
- queue.push(t);
- // pthread_mutex_unlock( &mutex );
- mutex.unlock();
- // Unlock mutex
-
- semaphore.post();
- //sem_post(&semaphore);
- }
-
- T pop() {
- semaphore.wait();
- // sem_wait(&semaphore);
- T t;
-
- // Lock mutex
- // pthread_mutex_lock( &mutex );
- mutex.lock();
- t = queue.front();
- queue.pop();
- // pthread_mutex_unlock( &mutex );
- mutex.unlock();
- // Unlock mutex
-
- return t;
- }
-
- int size() {
- int sz;
-
- // Lock mutex
- // pthread_mutex_lock( &mutex );
- mutex.lock();
- sz = queue.size();
- // pthread_mutex_unlock( &mutex );
- mutex.unlock();
- // Unlock mutex
-
- return sz;
- }
+ void push(T t);
+ T pop();
+ int size();
private:
std::queue<T> queue;