• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdegraphics API Reference
  • KDE Home
  • Contact Us
 

libs/libkdcraw/libkdcraw

  • sources
  • kde-4.14
  • kdegraphics
  • libs
  • libkdcraw
  • libkdcraw
ractionthreadbase.cpp
Go to the documentation of this file.
1 
28 #include "ractionthreadbase.moc"
29 
30 // Qt includes
31 
32 #include <QMutexLocker>
33 
34 // KDE includes
35 
36 #include <kurl.h>
37 #include <kdebug.h>
38 #include <ThreadWeaver/JobCollection>
39 #include <ThreadWeaver/Weaver>
40 #include <threadweaver/ThreadWeaver.h>
41 #include <threadweaver/Job.h>
42 #include <threadweaver/DebuggingAids.h>
43 #include <solid/device.h>
44 
45 // Local includes
46 
47 #include "ractionthreadbase_p.h"
48 
49 using namespace Solid;
50 
51 namespace KDcrawIface
52 {
53 
54 RActionThreadBase::RActionThreadBase(QObject* const parent)
55  : QThread(parent), d(new Private)
56 {
57  const int maximumNumberOfThreads = qMax(Device::listFromType(DeviceInterface::Processor).count(), 1);
58  d->log = new RWeaverObserver(this);
59  d->weaver = new Weaver(this);
60  d->weaver->registerObserver(d->log);
61  d->weaver->setMaximumNumberOfThreads(maximumNumberOfThreads);
62  kDebug() << "Starting Main Thread";
63 }
64 
65 RActionThreadBase::~RActionThreadBase()
66 {
67  kDebug() << "calling action thread destructor";
68  // cancel the thread
69  cancel();
70  // wait for the thread to finish
71  wait();
72 
73  delete d->log;
74  delete d->weaver;
75  delete d;
76 }
77 
78 void RActionThreadBase::setMaximumNumberOfThreads(int n)
79 {
80  d->weaver->setMaximumNumberOfThreads(n);
81 }
82 
83 void RActionThreadBase::slotFinished()
84 {
85  kDebug() << "Finish Main Thread";
86  d->weaverRunning = false;
87  d->condVarJobs.wakeAll();
88  emit QThread::finished();
89 }
90 
91 void RActionThreadBase::cancel()
92 {
93  kDebug() << "Cancel Main Thread";
94  QMutexLocker lock(&d->mutex);
95  d->todo.clear();
96  d->running = false;
97  d->weaverRunning = true;
98  d->weaver->requestAbort();
99  d->weaver->dequeue();
100  d->condVarJobs.wakeAll();
101 }
102 
103 void RActionThreadBase::finish()
104 {
105  d->weaver->finish();
106 }
107 
108 bool RActionThreadBase::isEmpty() const
109 {
110  return d->todo.isEmpty();
111 }
112 
113 void RActionThreadBase::appendJob(JobCollection* const job)
114 {
115  QMutexLocker lock(&d->mutex);
116  d->todo << job;
117  d->condVarJobs.wakeAll();
118 }
119 
120 void RActionThreadBase::run()
121 {
122  d->running = true;
123  d->weaverRunning = false;
124  kDebug() << "In action thread Run";
125 
126  while (d->running)
127  {
128  JobCollection* t = 0;
129  {
130  QMutexLocker lock(&d->mutex);
131 
132  if (!isEmpty() && !d->weaverRunning)
133  {
134  t = d->todo.takeFirst();
135  }
136  else
137  {
138  d->condVarJobs.wait(&d->mutex);
139  }
140  }
141 
142  if (t)
143  {
144  connect(t, SIGNAL(done(ThreadWeaver::Job*)),
145  this, SLOT(slotFinished()));
146 
147  connect(t, SIGNAL(done(ThreadWeaver::Job*)),
148  t, SLOT(deleteLater()));
149 
150  d->weaverRunning = true;
151  d->weaver->enqueue(t);
152  }
153  }
154 
155  d->weaver->finish();
156  kDebug() << "Exiting Action Thread";
157 }
158 
159 } // namespace KDcrawIface
QList::clear
void clear()
KDcrawIface::RActionThreadBase::isEmpty
bool isEmpty() const
Return true if list of pending jobs to process is empty.
Definition: ractionthreadbase.cpp:108
KDcrawIface::RActionThreadBase::Private::todo
QList< JobCollection * > todo
Definition: ractionthreadbase_p.h:98
KDcrawIface::RActionThreadBase::Private::weaver
Weaver * weaver
Definition: ractionthreadbase_p.h:100
KDcrawIface::RActionThreadBase::slotFinished
void slotFinished()
Definition: ractionthreadbase.cpp:83
KDcrawIface::RActionThreadBase::~RActionThreadBase
~RActionThreadBase()
Definition: ractionthreadbase.cpp:65
KDcrawIface::RActionThreadBase::cancel
void cancel()
Definition: ractionthreadbase.cpp:91
KDcrawIface::RActionThreadBase::Private::running
volatile bool running
Definition: ractionthreadbase_p.h:93
QObject
QList::isEmpty
bool isEmpty() const
KDcrawIface::RActionThreadBase::finish
void finish()
Definition: ractionthreadbase.cpp:103
QWaitCondition::wait
bool wait(QMutex *mutex, unsigned long time)
QObject::deleteLater
void deleteLater()
KDcrawIface::RActionThreadBase::appendJob
void appendJob(JobCollection *const job)
Append a collection of jobs to process in pending list.
Definition: ractionthreadbase.cpp:113
KDcrawIface::RActionThreadBase::setMaximumNumberOfThreads
void setMaximumNumberOfThreads(int n)
Adjust maximum number of thread used to parallelize collection of job processing. ...
Definition: ractionthreadbase.cpp:78
KDcrawIface::RActionThreadBase::Private::weaverRunning
volatile bool weaverRunning
Definition: ractionthreadbase_p.h:94
QThread::wait
bool wait(unsigned long time)
QList::takeFirst
T takeFirst()
KDcrawIface::RActionThreadBase::Private::mutex
QMutex mutex
Definition: ractionthreadbase_p.h:97
KDcrawIface::RActionThreadBase::Private::condVarJobs
QWaitCondition condVarJobs
Definition: ractionthreadbase_p.h:96
QMutexLocker
KDcrawIface::RWeaverObserver
RWeaverObserver is a simple wrapper to plug on the ActionThread class to prints debug messages when s...
Definition: ractionthreadbase_p.h:61
QThread
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
KDcrawIface::RActionThreadBase::run
void run()
Definition: ractionthreadbase.cpp:120
KDcrawIface::RActionThreadBase::Private
Definition: ractionthreadbase_p.h:81
QWaitCondition::wakeAll
void wakeAll()
KDcrawIface::RActionThreadBase::Private::log
RWeaverObserver * log
Definition: ractionthreadbase_p.h:101
QThread::finished
void finished()
ractionthreadbase_p.h
===========================================================This file is a part of digiKam project htt...
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:19:36 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

libs/libkdcraw/libkdcraw

Skip menu "libs/libkdcraw/libkdcraw"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdegraphics API Reference

Skip menu "kdegraphics API Reference"
  •     libkdcraw
  •     libkexiv2
  •     libkipi
  •     libksane
  • okular

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal