Files

37 lines
692 B
C
Raw Permalink Normal View History

2017-03-17 14:48:10 +01:00
#ifndef GB_GBTHREADQUEUE_H
#define GB_GBTHREADQUEUE_H
#include <queue>
#include <pthread.h>
2017-04-25 11:22:36 +02:00
#include <atomic>
2017-03-17 14:48:10 +01:00
typedef void (*queue_func_t)(void *item);
class GbThreadQueue {
public:
GbThreadQueue();
~GbThreadQueue();
bool initialize(queue_func_t processFunc, const char *threadName);
void finalize();
2017-03-27 12:47:00 +02:00
// we are not responsible for cleaning up memory used by item
2017-03-17 14:48:10 +01:00
void addItem(void *item);
bool isEmpty();
private:
static void* thread_queue_function(void *args);
std::queue<void*> m_queue;
pthread_mutex_t m_queueMtx;
pthread_cond_t m_queueCondNotEmpty;
pthread_t m_thread;
queue_func_t m_func;
2017-04-25 11:22:36 +02:00
std::atomic<bool> m_stop;
2017-03-17 14:48:10 +01:00
bool m_started;
};
#endif //GB_GBTHREADQUEUE_H