21 #include <abstractpropertytype.h>
22 #include "listplusplus.h"
25 #include <condition_variable>
26 #include <unordered_set>
32 template <
typename T,
class Pred = std::equal_to<T> >
36 Queue(
bool unique =
false,
bool blocking =
false)
37 :mUnique(unique), mBlocking(blocking)
49 std::lock_guard<std::mutex> lock(mutex);
56 std::unique_lock<std::mutex> lock(mutex);
67 throw std::runtime_error(
"nothing in queue");
69 auto itr = mQueue.begin();
78 virtual void append(T item)
81 std::lock_guard<std::mutex> lock(mutex);
82 if(contains(mQueue, item))
84 mQueue.erase(std::find(mQueue.begin(), mQueue.end(), item));
86 mQueue.push_back(item);
97 std::lock_guard<std::mutex> lock(mutex);
98 removeOne(&mQueue, item);
105 std::condition_variable cond;
106 std::vector<T> mQueue;
109 template <
typename T,
class Pred = std::equal_to<T> >
116 template <
typename T,
class Pred = std::equal_to<T> >
120 typedef function<void (Queue<T, Pred> *)> AsyncQueueWatcherCallback;
122 : callback(cb), mMaxQueueSize(queueSize)
125 static GSourceFuncs funcs = {prepare, check, dispatch, finalize};
129 watch->queue = queue;
130 watch->minQueueSize = queueSize;
132 gint p = G_PRIORITY_DEFAULT;
135 p = G_PRIORITY_DEFAULT;
141 g_source_set_priority(source, p);
142 g_source_set_callback(source,
nullptr,
this,
nullptr);
144 g_source_attach(source,
nullptr);
145 g_source_unref(source);
148 AsyncQueueWatcherCallback callback;
152 AsyncQueueWatcher(){}
158 static gboolean prepare(GSource *source, gint *timeout)
166 return s->queue->count() > s->minQueueSize;
169 static gboolean check(GSource *source)
176 return s->queue->count() > s->minQueueSize;
179 static gboolean dispatch(GSource *source, GSourceFunc callback, gpointer userData)
188 watcher->callback(s->queue);
192 static void finalize(GSource* source)
Definition: abstractpropertytype.h:80
Definition: asyncqueue.hpp:33
Definition: asyncqueue.hpp:117
Definition: asyncqueue.hpp:110
Definition: abstractpropertytype.h:252
Priority
The Priority enum describes prority of the property type.
Definition: abstractpropertytype.h:77
Definition: abstractpropertytype.h:81
Definition: abstractpropertytype.h:79