mirror of
https://gitlab.com/pholy/OSCAR-code.git
synced 2025-04-05 02:30:44 +00:00
Yet more Multithread stuff
This commit is contained in:
parent
526eb88a4e
commit
dcdb9549d4
@ -370,12 +370,14 @@ void gThread::run()
|
||||
{
|
||||
m_running=true;
|
||||
while (m_running) {
|
||||
mutex.lock(); // hang until a paint event unlocks it..
|
||||
//if (mutex.tryLock(1000)) {
|
||||
graph->lockPaintMutex(); // will hang until in paintGL
|
||||
// do nothing..
|
||||
graph->unlockPaintMutex(); // unlock straight away
|
||||
if (mutex.tryLock()) {
|
||||
if (!m_running) break;
|
||||
graph->paint(m_left,m_top,m_width,m_height);
|
||||
graph->threadDone();
|
||||
//}
|
||||
}
|
||||
}
|
||||
}
|
||||
void gThread::paint(int originX, int originY, int width, int height)
|
||||
@ -384,6 +386,7 @@ void gThread::paint(int originX, int originY, int width, int height)
|
||||
m_left=originX;
|
||||
m_width=width;
|
||||
m_height=height;
|
||||
//wc.wakeAll();
|
||||
mutex.unlock(); // this is the signal to start
|
||||
}
|
||||
|
||||
@ -418,6 +421,9 @@ gGraph::~gGraph()
|
||||
delete m_thread;
|
||||
delete m_quad;
|
||||
}
|
||||
void gGraph::lockPaintMutex() { m_graphview->inPaintMutex.lock(); }
|
||||
void gGraph::unlockPaintMutex() { m_graphview->inPaintMutex.unlock(); }
|
||||
|
||||
bool gGraph::isEmpty()
|
||||
{
|
||||
bool empty=true;
|
||||
@ -1297,6 +1303,7 @@ void gGraphView::initializeGL()
|
||||
glDisable(GL_LIGHTING);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
inPaintMutex.lock();
|
||||
}
|
||||
|
||||
void gGraphView::resizeGL(int w, int h)
|
||||
@ -1316,6 +1323,8 @@ void gGraphView::paintGL()
|
||||
if (width()<=0) return;
|
||||
if (height()<=0) return;
|
||||
|
||||
inPaintMutex.unlock();
|
||||
|
||||
QTime time;
|
||||
time.start();
|
||||
|
||||
@ -1346,7 +1355,7 @@ void gGraphView::paintGL()
|
||||
bool threaded;
|
||||
|
||||
// Tempory hack using this pref..
|
||||
if (pref["EnableMultithreading"].toBool() && (m_idealthreads>1)) {
|
||||
if (pref["EnableMultithreading"].toBool()) { // && (m_idealthreads>1)) {
|
||||
threaded=true;
|
||||
} else threaded=false;
|
||||
|
||||
@ -1368,7 +1377,7 @@ void gGraphView::paintGL()
|
||||
//QFuture<void> future = QtConcurrent::run(m_graphs[i],&gGraph::paint,px,py,width()-titleWidth,h);
|
||||
m_graphs[i]->threadStart(); // this only happens once.. It stays dormant when not in use.
|
||||
m_graphs[i]->thread()->paint(px,py,width()-titleWidth,h);
|
||||
m_graphs[i]->thread()->setPriority(QThread::HighPriority);
|
||||
//m_graphs[i]->thread()->setPriority(QThread::HighPriority);
|
||||
} else {
|
||||
m_graphs[i]->paint(px,py,width()-titleWidth,h);
|
||||
}
|
||||
@ -1393,14 +1402,17 @@ void gGraphView::paintGL()
|
||||
}
|
||||
int thr;
|
||||
|
||||
|
||||
if (threaded) {
|
||||
thr=m_idealthreads;
|
||||
// wait till all the threads are done
|
||||
masterlock->acquire(m_idealthreads); // ask for all the CPU's back..
|
||||
masterlock->release(m_idealthreads);
|
||||
} else thr=1;
|
||||
|
||||
//((QGLContext*)context())->makeCurrent();
|
||||
inPaintMutex.lock();
|
||||
|
||||
//((QGLContext*)context())->makeCurrent();
|
||||
|
||||
backlines->draw();
|
||||
for (int i=0;i<m_graphs.size();i++) {
|
||||
@ -1417,8 +1429,9 @@ void gGraphView::paintGL()
|
||||
}
|
||||
//glDisable(GL_TEXTURE_2D);
|
||||
//glDisable(GL_DEPTH_TEST);
|
||||
|
||||
swapBuffers(); // Dump to screen.
|
||||
|
||||
|
||||
//qDebug() << "Graph Prep,Draw" << el << "," << time.elapsed()-el << "ms x" << thr;
|
||||
}
|
||||
|
||||
|
@ -265,6 +265,8 @@ public:
|
||||
GLBuffer * backlines();
|
||||
GLBuffer * quads();
|
||||
short m_marginleft, m_marginright, m_margintop, m_marginbottom;
|
||||
void lockPaintMutex();
|
||||
void unlockPaintMutex();
|
||||
protected:
|
||||
//void invalidate();
|
||||
|
||||
@ -341,6 +343,7 @@ public:
|
||||
void setEmptyText(QString s) { m_emptytext=s; }
|
||||
QMutex text_mutex;
|
||||
QMutex gl_mutex;
|
||||
QMutex inPaintMutex;
|
||||
void setDay(Day * day);
|
||||
QSemaphore * masterlock;
|
||||
bool useThreads() { return m_idealthreads>1; }
|
||||
|
@ -8,7 +8,12 @@
|
||||
#include <QDebug>
|
||||
#include "gXAxis.h"
|
||||
|
||||
const qint64 divisors[]={2419200000,1814400000,1209600000,604800000,259200000, 172800000, 86400000,2880000,14400000,7200000,3600000,2700000,1800000,1200000,900000,600000,300000,120000,60000,45000,30000,20000,15000,10000,5000,2000,1000,100,50,10};
|
||||
const quint64 divisors[]={
|
||||
2419200000LL, 1814400000L, 1209600000L, 604800000L, 259200000L,
|
||||
172800000L, 86400000,2880000,14400000,7200000,3600000,2700000,
|
||||
1800000,1200000,900000,600000,300000,120000,60000,45000,30000,
|
||||
20000,15000,10000,5000,2000,1000,100,50,10
|
||||
};
|
||||
const int divcnt=sizeof(divisors)/sizeof(int);
|
||||
|
||||
gXAxis::gXAxis(QColor col,bool fadeout)
|
||||
|
Loading…
Reference in New Issue
Block a user