code style
This commit is contained in:
+14
-12
@@ -16,12 +16,12 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef LIBUTILS_QUEUE_H_
|
||||
#define LIBUTILS_QUEUE_H_
|
||||
#ifndef LIB_UTILS_QUEUE_H_
|
||||
#define LIB_UTILS_QUEUE_H_
|
||||
|
||||
#include <list>
|
||||
#include <pthread.h>
|
||||
#include <errno.h>
|
||||
#include <list>
|
||||
#include "clock.h"
|
||||
|
||||
/** \file queue.h */
|
||||
@@ -82,22 +82,23 @@ 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) {
|
||||
if (timeout > 0) {
|
||||
struct timespec t;
|
||||
clockGettime(&t);
|
||||
t.tv_sec += timeout;
|
||||
while (m_queue.empty()) {
|
||||
if (pthread_cond_timedwait(&m_cond, &m_mutex, &t)==ETIMEDOUT)
|
||||
if (pthread_cond_timedwait(&m_cond, &m_mutex, &t) == ETIMEDOUT) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (m_queue.empty())
|
||||
if (m_queue.empty()) {
|
||||
item = NULL;
|
||||
else {
|
||||
} else {
|
||||
item = m_queue.front();
|
||||
m_queue.pop_front();
|
||||
}
|
||||
@@ -111,7 +112,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);
|
||||
@@ -138,10 +139,11 @@ public:
|
||||
{
|
||||
T item;
|
||||
pthread_mutex_lock(&m_mutex);
|
||||
if (m_queue.empty())
|
||||
if (m_queue.empty()) {
|
||||
item = NULL;
|
||||
else
|
||||
} else {
|
||||
item = m_queue.front();
|
||||
}
|
||||
pthread_mutex_unlock(&m_mutex);
|
||||
return item;
|
||||
}
|
||||
@@ -158,4 +160,4 @@ private:
|
||||
|
||||
};
|
||||
|
||||
#endif // LIBUTILS_QUEUE_H_
|
||||
#endif // LIB_UTILS_QUEUE_H_
|
||||
|
||||
Reference in New Issue
Block a user