threaded brush preview rendering

This commit is contained in:
2019-02-28 14:47:06 +01:00
parent e59dd66b46
commit f20f935d43
5 changed files with 71 additions and 4 deletions

View File

@@ -151,18 +151,18 @@ template<typename T> struct cbuffer
template<typename T, int Max = 0>
class BlockingQueue
{
public:
std::deque<T> q;
std::condition_variable post_cv;
std::condition_variable get_cv;
mutable std::mutex mutex;
public:
volatile bool unlocked = false;
BlockingQueue() = default;
BlockingQueue(const BlockingQueue& other) = delete;
BlockingQueue& operator=(const BlockingQueue& other) = delete;
BlockingQueue(BlockingQueue&& other) : q(std::move(q)) { }
BlockingQueue& operator=(BlockingQueue&& other) { q = std::move(q); return *this; }
void Post(T&& pkt)
void Post(T pkt)
{
std::unique_lock<std::mutex> lock(mutex);
if (Max > 0)
@@ -170,7 +170,19 @@ public:
post_cv.wait(lock, [&]() { return unlocked | (q.size() < Max); });
if (q.size() >= Max) return;
}
q.push_back(std::forward<T>(pkt));
q.push_back(pkt);
get_cv.notify_one();
}
void PostUnique(T pkt)
{
std::unique_lock<std::mutex> lock(mutex);
if (Max > 0)
{
post_cv.wait(lock, [&]() { return unlocked | (q.size() < Max); });
if (q.size() >= Max) return;
}
if (std::find(q.begin(), q.end(), pkt) == q.end());
q.push_back(pkt);
get_cv.notify_one();
}
T Get()