[Kst] extragear/graphics/kst/src/libkstapp
George Staikos
staikos at kde.org
Sun Nov 5 18:41:42 CET 2006
SVN commit 602320 by staikos:
make it actually work except for one small issue: curves aren't added to the
curves updated list
M +84 -50 updatethread-multicore.cpp
--- trunk/extragear/graphics/kst/src/libkstapp/updatethread-multicore.cpp #602319:602320
@@ -30,6 +30,8 @@
#include "kstvcurve.h"
#include "threadevents.h"
+#define THREADJOBS 3
+
// 0 - none, 1 - some, 2 - lots, 3 - too much
#define UPDATEDEBUG 1
@@ -46,12 +48,69 @@
}
+class UpdateJob : public QThread {
+ public:
+ UpdateJob(UpdateThread *t) : QThread(), _t(t) {
+ }
+
+ virtual ~UpdateJob() {
+ }
+
+ protected:
+ virtual void run() {
+ for (KstObjectPtr o;;) {
+ if (!o) {
+ o = _t->dequeueUpdate();
+ }
+
+ if (o) {
+ o->writeLock();
+ KstObject::UpdateType rc = o->update(_t->_updateCounter);
+ o->unlock();
+ if (rc == KstObject::UPDATE) {
+ _t->_updateResult = rc;
+ }
+ }
+
+ o = 0L;
+
+ if (_t->finished()) {
+ break;
+ }
+
+ o = _t->dequeueUpdate();
+
+ if (o) {
+ continue;
+ }
+
+ _t->_queueCondition.wait();
+
+ if (_t->finished()) {
+ break;
+ }
+ }
+ // FIXME need to signify to the update thread that we're dead
+ }
+
+ UpdateThread *_t;
+};
+
+
void UpdateThread::run() {
bool force;
int updateTime;
_done = false;
+ QValueList<UpdateJob *> jobs;
+
+ for (int i = 0; i < THREADJOBS; ++i) {
+ UpdateJob *j = new UpdateJob(this);
+ jobs.append(j);
+ j->start();
+ }
+
while (!_done) {
_statusMutex.lock();
updateTime = _updateTime;
@@ -127,6 +186,10 @@
_done = true; // should be redundant
_queueCondition.wakeAll();
+ usleep(1000);
+ for (QValueList<UpdateJob*>::Iterator i = jobs.begin(); i != jobs.end(); ++i) {
+ delete *i;
+ }
QApplication::postEvent(_doc, new ThreadEvent(ThreadEvent::Done));
}
@@ -176,11 +239,25 @@
kstdDebug() << "5 Returning from scan with U=" << (int)U << endl;
#endif
waitForJobs();
+ for (uint j = 0; j <= i; ++j) {
+ // Note: this should probably be read locked
+ if (cl[i]->lastUpdateResult() == KstObject::UPDATE) {
+ _updatedCurves.append(cl[i]);
+ }
+ }
return updateResult();
}
}
+
waitForJobs();
+ for (KstBaseCurveList::Iterator i = cl.begin(); i != cl.end(); ++i) {
+ // Note: this should probably be read locked
+ if ((*i)->lastUpdateResult() == KstObject::UPDATE) {
+ _updatedCurves.append(*i);
+ }
+ }
+
// Update all data objects
for (uint i = 0; i < dol.count(); ++i) {
KstDataObjectPtr dp = dol[i];
@@ -297,54 +374,7 @@
}
-class UpdateJob : public QThread {
- public:
- UpdateJob(UpdateThread *t) : QThread(), _t(t) {
- }
- virtual ~UpdateJob() {
- }
-
- protected:
- virtual void run() {
- for (KstObjectPtr o;;) {
- if (!o) {
- o = _t->dequeueUpdate();
- }
-
- if (o) {
- o->writeLock();
- KstObject::UpdateType rc = o->update(_t->_updateCounter);
- o->unlock();
- if (rc == KstObject::UPDATE) {
- _t->_updateResult = rc;
- }
- }
-
- o = 0L;
-
- if (_t->finished()) {
- break;
- }
-
- o = _t->dequeueUpdate();
-
- if (o) {
- continue;
- }
-
- _t->_queueCondition.wait();
-
- if (_t->finished()) {
- break;
- }
- }
- }
-
- UpdateThread *_t;
-};
-
-
void UpdateThread::startNewUpdate() {
//_resultMutex.lock();
_updateResult = KstObject::NO_CHANGE;
@@ -355,9 +385,13 @@
KstObjectPtr UpdateThread::dequeueUpdate() {
KstObjectPtr rc;
_updateQueueMutex.lock();
- // We could make this smarter if we had isLocked()
- rc = _updateQueue.first();
- _updateQueue.pop_front();
+ if (_updateQueue.isEmpty()) {
+ _emptyQueueCondition.wakeAll();
+ } else {
+ // We could make this smarter if we had isLocked()
+ rc = _updateQueue.first();
+ _updateQueue.pop_front();
+ }
_updateQueueMutex.unlock();
return rc;
}
More information about the Kst
mailing list