threaded brush preview rendering
This commit is contained in:
18
src/util.h
18
src/util.h
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user