documentation for class WQueue and Notify added.

This commit is contained in:
Roland Jax
2014-11-16 10:08:58 +01:00
parent 5db9c5c774
commit e4e709ec6a
4 changed files with 101 additions and 19 deletions
+30 -1
View File
@@ -23,22 +23,36 @@
#include <list>
#include <pthread.h>
template <typename T> class WQueue
/**
* @brief queue class template for all kinds data types with exclusiv lock.
*/
template <typename T>
class WQueue
{
public:
/**
* @brief constructs a new instance.
*/
WQueue()
{
pthread_mutex_init(&m_mutex, NULL);
pthread_cond_init(&m_cond, NULL);
}
/**
* @brief destructor.
*/
~WQueue()
{
pthread_mutex_destroy(&m_mutex);
pthread_cond_destroy(&m_cond);
}
/**
* @brief add a new item to the end of queue.
* @param item
*/
void add(T item)
{
pthread_mutex_lock(&m_mutex);
@@ -49,6 +63,10 @@ public:
pthread_mutex_unlock(&m_mutex);
}
/**
* @brief remove the first item from queue.
* @return the item
*/
T remove()
{
pthread_mutex_lock(&m_mutex);
@@ -64,6 +82,10 @@ public:
return item;
}
/**
* @brief return the first item from queue without remove.
* @return the item
*/
T next()
{
pthread_mutex_lock(&m_mutex);
@@ -78,6 +100,10 @@ public:
return item;
}
/**
* @brief the number of entries inside queue.
* @return the size
*/
int size()
{
pthread_mutex_lock(&m_mutex);
@@ -90,8 +116,11 @@ public:
}
private:
/** the queue itself */
std::list<T> m_queue;
/** mutex variable for exclusive lock */
pthread_mutex_t m_mutex;
/** condition variable for exclusive lock */
pthread_cond_t m_cond;
};