ThreadWeaver

queuestream.cpp
1/* -*- C++ -*-
2 This file is part of ThreadWeaver, a KDE framework.
3
4 SPDX-FileCopyrightText: 2013 Mirko Boehm <mirko@kde.org>
5
6 SPDX-License-Identifier: LGPL-2.0-or-later
7*/
8
9#include <QList>
10
11#include "queue.h"
12#include "queueing.h"
13#include "queuestream.h"
14
15namespace ThreadWeaver
16{
17class Q_DECL_HIDDEN QueueStream::Private
18{
19public:
20 Private(Queue *w)
21 : weaver(w)
22 {
23 }
24 Queue *weaver;
26};
27
28QueueStream::QueueStream(Queue *queue)
29 : d(new Private(queue))
30{
31 Q_ASSERT(queue);
32}
33
34QueueStream::~QueueStream()
35{
36 flush();
37 delete d;
38}
39
40void ThreadWeaver::QueueStream::add(const ThreadWeaver::JobPointer &job)
41{
42 d->jobs.append(job);
43}
44
45void QueueStream::flush()
46{
47 if (d->jobs.isEmpty()) {
48 return;
49 }
50 Q_ASSERT(d->weaver);
51 d->weaver->enqueue(d->jobs);
52 d->jobs.clear();
53}
54
55QueueStream &QueueStream::operator<<(const JobPointer &job)
56{
57 add(job);
58 return *this;
59}
60
61QueueStream &QueueStream::operator<<(JobInterface *job)
62{
63 add(make_job(job));
64 return *this;
65}
66
67QueueStream &QueueStream::operator<<(Job &job)
68{
69 add(make_job_raw(&job));
70 return *this;
71}
72
73/** @brief Return a stream the enqueues jobs in the ThreadWeaver global queue.
74 * Using this is synonymous to Weaver::instance()::stream(). */
75QueueStream stream()
76{
77 return QueueStream(Queue::instance());
78}
79
80}
static ThreadWeaver::Queue * instance()
Access the application-global Queue.
Definition queue.cpp:152
void enqueue(const QList< JobPointer > &jobs) override
Queue a vector of jobs.
Definition queue.cpp:167
QTextStream & flush(QTextStream &stream)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 8 2024 11:58:32 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.