Yeah that would've blown up.
This commit is contained in:
parent
8def91b0a8
commit
dd8683b9e8
@ -7,8 +7,10 @@ QMutex Worker::workerLock;
|
||||
|
||||
void Worker::queue(WorkerContext *context) {
|
||||
QMutexLocker ml(&lock);
|
||||
context->pixmap = context->pixmap.copy();
|
||||
qqueue.enqueue(context);
|
||||
_WorkerContext *c = new _WorkerContext;
|
||||
c->image = context->pixmap.toImage().convertToFormat(context->targetFormat);
|
||||
c->consumer = context->consumer;
|
||||
qqueue.enqueue(c);
|
||||
}
|
||||
|
||||
void Worker::init() {
|
||||
@ -45,8 +47,8 @@ void Worker::process() {
|
||||
while (!ended()) {
|
||||
lock.lock();
|
||||
if (!qqueue.isEmpty()) {
|
||||
WorkerContext *c = qqueue.dequeue();
|
||||
c->consumer(c->pixmap.toImage().convertToFormat(c->targetFormat));
|
||||
_WorkerContext *c = qqueue.dequeue();
|
||||
c->consumer(c->image);
|
||||
}
|
||||
lock.unlock();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100)); // STL likes it's scopes
|
||||
|
@ -15,6 +15,11 @@ struct WorkerContext {
|
||||
std::function<void(QImage)> consumer;
|
||||
};
|
||||
|
||||
struct _WorkerContext {
|
||||
QImage image;
|
||||
std::function<void(QImage)> consumer;
|
||||
};
|
||||
|
||||
class Worker : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
@ -27,7 +32,7 @@ private:
|
||||
QMutex lock;
|
||||
QMutex endLock;
|
||||
QThread *thr;
|
||||
QQueue<WorkerContext *> qqueue; // Say that ten times as fast
|
||||
QQueue<_WorkerContext *> qqueue; // Say that ten times as fast
|
||||
bool _ended;
|
||||
|
||||
void _queue(WorkerContext *context);
|
||||
|
Loading…
x
Reference in New Issue
Block a user