privacore-open-source-searc.../GbThreadQueue.h
2017-04-25 11:22:36 +02:00

37 lines
692 B
C++

#ifndef GB_GBTHREADQUEUE_H
#define GB_GBTHREADQUEUE_H
#include <queue>
#include <pthread.h>
#include <atomic>
typedef void (*queue_func_t)(void *item);
class GbThreadQueue {
public:
GbThreadQueue();
~GbThreadQueue();
bool initialize(queue_func_t processFunc, const char *threadName);
void finalize();
// we are not responsible for cleaning up memory used by item
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;
std::atomic<bool> m_stop;
bool m_started;
};
#endif //GB_GBTHREADQUEUE_H