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);
68 throw std::runtime_error(
"nothing in queue");
71 auto itr = mQueue.begin();
80 virtual void append(T item)
83 std::lock_guard<std::mutex> lock(mutex);
84 if(contains(mQueue, item))
86 mQueue.erase(std::find(mQueue.begin(), mQueue.end(), item));
88 mQueue.push_back(item);
99 std::lock_guard<std::mutex> lock(mutex);
100 removeOne(&mQueue, item);
107 std::condition_variable cond;
108 std::vector<T> mQueue;
111 template <
typename T,
class Pred = std::equal_to<T> >
118 template <
typename T,
class Pred = std::equal_to<T> >
122 typedef function<void (Queue<T, Pred> *)> AsyncQueueWatcherCallback;
124 : callback(cb), mMaxQueueSize(queueSize)
127 static GSourceFuncs funcs = {prepare, check, dispatch, finalize};
131 watch->queue = queue;
132 watch->minQueueSize = queueSize;
134 gint p = G_PRIORITY_DEFAULT;
137 p = G_PRIORITY_DEFAULT;
143 g_source_set_priority(source, p);
144 g_source_set_callback(source,
nullptr,
this,
nullptr);
146 g_source_attach(source,
nullptr);
147 g_source_unref(source);
150 AsyncQueueWatcherCallback callback;
154 AsyncQueueWatcher(){}
160 static gboolean prepare(GSource *source, gint *timeout)
168 return s->queue->count() > s->minQueueSize;
171 static gboolean check(GSource *source)
178 return s->queue->count() > s->minQueueSize;
181 static gboolean dispatch(GSource *source, GSourceFunc callback, gpointer userData)
190 watcher->callback(s->queue);
194 static void finalize(GSource* source)