code style

This commit is contained in:
john30
2017-01-14 15:02:10 +01:00
parent b3bb2e08ac
commit 54a6c0f673
32 changed files with 484 additions and 665 deletions
+12 -20
View File
@@ -33,15 +33,12 @@ using namespace std;
* @param T the item type.
*/
template <typename T>
class Queue
{
public:
class Queue {
public:
/**
* Constructor.
*/
Queue()
{
Queue() {
pthread_mutex_init(&m_mutex, NULL);
pthread_cond_init(&m_cond, NULL);
}
@@ -49,28 +46,26 @@ public:
/**
* Destructor.
*/
~Queue()
{
~Queue() {
pthread_mutex_destroy(&m_mutex);
pthread_cond_destroy(&m_cond);
}
private:
private:
/**
* Hidden copy constructor.
* @param src the object to copy from.
*/
Queue(const Queue& src);
public:
public:
/**
* Add an item to the end of queue.
* @param item the item to add.
*/
void push(T item)
{
void push(T item) {
pthread_mutex_lock(&m_mutex);
m_queue.push_back(item);
pthread_cond_broadcast(&m_cond);
@@ -82,8 +77,7 @@ public:
* @param timeout the maximum time in seconds to wait for the queue being filled, or 0 for no wait.
* @return the item, or NULL if no item is available within the specified time.
*/
T pop(int timeout = 0)
{
T pop(int timeout = 0) {
T item;
pthread_mutex_lock(&m_mutex);
if (timeout > 0) {
@@ -112,8 +106,7 @@ public:
* @param wait true to wait for the item to appear in the queue.
* @return whether the item was removed.
*/
bool remove(T item, bool wait = false)
{
bool remove(T item, bool wait = false) {
bool ret = false;
pthread_mutex_lock(&m_mutex);
do {
@@ -135,8 +128,7 @@ public:
* Return the first item in the queue without removing it.
* @return the item, or NULL if no item is available.
*/
T peek()
{
T peek() {
T item;
pthread_mutex_lock(&m_mutex);
if (m_queue.empty()) {
@@ -148,7 +140,8 @@ public:
return item;
}
private:
private:
/** the queue itself */
list<T> m_queue;
@@ -157,7 +150,6 @@ private:
/** condition variable for exclusive lock */
pthread_cond_t m_cond;
};
#endif // LIB_UTILS_QUEUE_H_