More threading stuff

This commit is contained in:
Mark Watkins 2011-09-01 13:37:25 +10:00
parent 2d6f0566de
commit 958208f36d
7 changed files with 65 additions and 100 deletions

View File

@ -40,13 +40,10 @@ qint64 gFlagsGroup::Maxx()
} }
return 0; return 0;
} }
void gFlagsGroup::SetDay(Day * d)
void gFlagsGroup::paint(gGraph &w, int left, int top, int width, int height)
{ {
if (!m_visible) return; LayerGroup::SetDay(d);
//if (!m_day) return; lvisible.clear();
QVector<gFlagsLine *> lvisible;
for (int i=0;i<layers.size();i++) { for (int i=0;i<layers.size();i++) {
gFlagsLine *f=dynamic_cast<gFlagsLine *>(layers[i]); gFlagsLine *f=dynamic_cast<gFlagsLine *>(layers[i]);
if (!f) continue; if (!f) continue;
@ -55,6 +52,14 @@ void gFlagsGroup::paint(gGraph &w, int left, int top, int width, int height)
lvisible.push_back(f); lvisible.push_back(f);
} }
} }
}
void gFlagsGroup::paint(gGraph &w, int left, int top, int width, int height)
{
if (!m_visible) return;
if (!m_day) return;
int vis=lvisible.size(); int vis=lvisible.size();
float barh=float(height)/float(vis); float barh=float(height)/float(vis);
float linetop=top; float linetop=top;
@ -83,9 +88,11 @@ gFlagsLine::gFlagsLine(ChannelID code,QColor flag_color,QString label,bool alway
:Layer(code),m_label(label),m_always_visible(always_visible),m_flt(flt),m_flag_color(flag_color) :Layer(code),m_label(label),m_always_visible(always_visible),m_flt(flt),m_flag_color(flag_color)
{ {
addGLBuf(quads=new GLBuffer(flag_color,2048,GL_QUADS)); addGLBuf(quads=new GLBuffer(flag_color,2048,GL_QUADS));
addGLBuf(lines=new GLBuffer(flag_color,2048,GL_LINES)); addGLBuf(lines=new GLBuffer(flag_color,1024,GL_LINES));
quads->setAntiAlias(true); quads->setAntiAlias(true);
lines->setAntiAlias(true); lines->setAntiAlias(true);
GetTextExtent(m_label,m_lx,m_ly);
//m_static.setText(m_label);;
} }
gFlagsLine::~gFlagsLine() gFlagsLine::~gFlagsLine()
{ {
@ -115,9 +122,10 @@ void gFlagsLine::paint(gGraph & w,int left, int top, int width, int height)
// Draw text label // Draw text label
int x,y; //int x,y;
GetTextExtent(m_label,x,y); //GetTextExtent(m_label,x,y);
w.renderText(m_label,left-x-10,top+(height/2)+(y/2)); //w.DrawStaticText(m_static,left-m_lx-10,top+(height/2)-(m_ly/2));
w.renderText(m_label,left-m_lx-10,top+(height/2)+(m_ly/2));
float x1,x2; float x1,x2;
float bartop=top+2; float bartop=top+2;
@ -146,6 +154,7 @@ void gFlagsLine::paint(gGraph & w,int left, int top, int width, int height)
if (quads->full()) { verts_exceeded=true; break; } if (quads->full()) { verts_exceeded=true; break; }
} }
} }
if (verts_exceeded) break;
} }
if (verts_exceeded) { if (verts_exceeded) {
qWarning() << "maxverts exceeded in gFlagsLine::plot()"; qWarning() << "maxverts exceeded in gFlagsLine::plot()";

View File

@ -7,6 +7,7 @@
#ifndef GFLAGSLINE_H #ifndef GFLAGSLINE_H
#define GFLAGSLINE_H #define GFLAGSLINE_H
#include <QStaticText>
#include "gGraphView.h" #include "gGraphView.h"
class gFlagsGroup; class gFlagsGroup;
@ -32,6 +33,8 @@ class gFlagsLine:public Layer
FlagType m_flt; FlagType m_flt;
QColor m_flag_color; QColor m_flag_color;
GLBuffer *quads, *lines; GLBuffer *quads, *lines;
int m_lx, m_ly;
//QStaticText m_static;
}; };
@ -44,10 +47,10 @@ public:
virtual void paint(gGraph & w,int left, int top, int width, int height); virtual void paint(gGraph & w,int left, int top, int width, int height);
virtual qint64 Minx(); virtual qint64 Minx();
virtual qint64 Maxx(); virtual qint64 Maxx();
virtual void SetDay(Day *);
protected: protected:
GLBuffer *quad1, *quad2, *lines; GLBuffer *quad1, *quad2, *lines;
QVector<gFlagsLine *> lvisible;
}; };
#endif // GFLAGSLINE_H #endif // GFLAGSLINE_H

View File

@ -300,7 +300,8 @@ void gThread::run()
{ {
m_running=true; m_running=true;
while (m_running) { while (m_running) {
if (mutex.tryLock(1000)) { //mutex.lock();
if (mutex.tryLock(500)) {
int originX=m_lastbounds.x(); int originX=m_lastbounds.x();
int originY=m_lastbounds.y(); int originY=m_lastbounds.y();
int width=m_lastbounds.width(); int width=m_lastbounds.width();
@ -308,6 +309,7 @@ void gThread::run()
graph->paint(originX,originY,width,height); graph->paint(originX,originY,width,height);
graph->threadDone(); graph->threadDone();
} }
this->yieldCurrentThread();
} }
} }
void gThread::paint(int originX, int originY, int width, int height) void gThread::paint(int originX, int originY, int width, int height)
@ -337,14 +339,14 @@ gGraph::gGraph(gGraphView *graphview,QString title,int height,short group) :
m_selecting_area=m_blockzoom=false; m_selecting_area=m_blockzoom=false;
m_lastx23=0; m_lastx23=0;
m_thread=new gThread(this);
if (m_graphview->useThreads()) m_thread->start();
quad=new GLBuffer(QColor(128,128,255,128),8,GL_QUADS); quad=new GLBuffer(QColor(128,128,255,128),8,GL_QUADS);
quad->forceAntiAlias(true); quad->forceAntiAlias(true);
m_thread=new gThread(this);
} }
gGraph::~gGraph() gGraph::~gGraph()
{ {
if (m_graphview->useThreads()) { if (m_thread->isRunning()) {
m_thread->die(); m_thread->die();
m_thread->wait(); m_thread->wait();
m_thread->exit(); m_thread->exit();
@ -365,8 +367,7 @@ bool gGraph::isEmpty()
} }
void gGraph::threadDone() void gGraph::threadDone()
{ {
// m_graphview->masterlock->release(1);
m_graphview->masterlock->release(1);
} }
void gGraph::drawGLBuf() void gGraph::drawGLBuf()
@ -435,10 +436,7 @@ void gGraph::renderText(QString text, int x,int y, float angle, QColor color, QF
void gGraph::paint(int originX, int originY, int width, int height) void gGraph::paint(int originX, int originY, int width, int height)
{ {
m_lastbounds=QRect(originX,originY,width,height); m_lastbounds=QRect(originX,originY,width,height);
/* int originX=m_lastbounds.x();
int originY=m_lastbounds.y();
int width=m_lastbounds.width();
int height=m_lastbounds.height(); */
/*glEnable(GL_BLEND); /*glEnable(GL_BLEND);
glBegin(GL_QUADS); glBegin(GL_QUADS);
glColor4f(1,1,1,0.4); // Gradient End glColor4f(1,1,1,0.4); // Gradient End
@ -462,6 +460,7 @@ void gGraph::paint(int originX, int originY, int width, int height)
originY+=m_margintop; originY+=m_margintop;
width-=m_marginleft+m_marginright; width-=m_marginleft+m_marginright;
height-=m_margintop+m_marginbottom; height-=m_margintop+m_marginbottom;
int lsize=m_layers.size();
for (int i=0;i<m_layers.size();i++) { for (int i=0;i<m_layers.size();i++) {
Layer *ll=m_layers[i]; Layer *ll=m_layers[i];
@ -509,7 +508,7 @@ void gGraph::paint(int originX, int originY, int width, int height)
quad->add(originX+m_selection.x()+m_selection.width(),originY+height-top-bottom, originX+m_selection.x(),originY+height-top-bottom); quad->add(originX+m_selection.x()+m_selection.width(),originY+height-top-bottom, originX+m_selection.x(),originY+height-top-bottom);
} }
m_graphview->masterlock->release(1);
/*m_graphview->gl_mutex.lock(); /*m_graphview->gl_mutex.lock();
((QGLContext *)m_graphview->context())->makeCurrent(); ((QGLContext *)m_graphview->context())->makeCurrent();
drawGLBuf(); drawGLBuf();
@ -952,9 +951,6 @@ gGraphView::gGraphView(QWidget *parent, gGraphView * shared) :
InitGraphs(); InitGraphs();
m_idealthreads=QThread::idealThreadCount(); m_idealthreads=QThread::idealThreadCount();
if (m_idealthreads<=0) m_idealthreads=1; if (m_idealthreads<=0) m_idealthreads=1;
//m_idealthreads*=2;
masterlock=new QSemaphore(m_idealthreads); masterlock=new QSemaphore(m_idealthreads);
} }
gGraphView::~gGraphView() gGraphView::~gGraphView()
@ -1180,10 +1176,6 @@ void gGraphView::resizeGL(int w, int h)
glLoadIdentity(); glLoadIdentity();
} }
void gGraphView::threadDone()
{
qDebug() << "Thread Done" << m_threadsrunning;
}
void gGraphView::paintGL() void gGraphView::paintGL()
{ {
@ -1222,6 +1214,7 @@ void gGraphView::paintGL()
threaded=true; threaded=true;
} else threaded=false; } else threaded=false;
threaded=true;
for (int i=0;i<m_graphs.size();i++) { for (int i=0;i<m_graphs.size();i++) {
if (m_graphs[i]->isEmpty() || !m_graphs[i]->visible()) continue; if (m_graphs[i]->isEmpty() || !m_graphs[i]->visible()) continue;
numgraphs++; numgraphs++;
@ -1235,38 +1228,33 @@ void gGraphView::paintGL()
if ((py + h + graphSpacer) >= 0) { if ((py + h + graphSpacer) >= 0) {
w=width(); w=width();
masterlock->acquire(1); // book an available CPU
if (threaded) { if (threaded) {
masterlock->acquire(1); // book an available CPU 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()->paint(px,py,width()-titleWidth,h);
//m_graphs[i]->thread()->start(QThread::HighestPriority);
//m_graphs[i]->thread()->wait();
} else { } else {
m_graphs[i]->paint(px,py,width()-titleWidth,h); m_graphs[i]->paint(px,py,width()-titleWidth,h);
} }
//glColor4f(0,0,0,1); bool r=m_graphs[i]->thread()->isRunning();
//if (i<numgraphs-1) {
// draw the splitter handle // draw the splitter handle
glBegin(GL_QUADS); glBegin(GL_QUADS);
glColor4f(.5,.5,.5,1.0); glColor4f(.5,.5,.5,1.0);
glVertex2f(0,py+h); glVertex2f(0,py+h);
glVertex2f(w,py+h); glVertex2f(w,py+h);
glColor4f(.7,.7,.7,1.0); glColor4f(.7,.7,.7,1.0);
glVertex2f(w,py+h+graphSpacer/2.0); glVertex2f(w,py+h+graphSpacer/2.0);
glVertex2f(0,py+h+graphSpacer/2.0); glVertex2f(0,py+h+graphSpacer/2.0);
glColor4f(1,1,1,1.0); glColor4f(1,1,1,1.0);
glVertex2f(0,py+h+graphSpacer/2.0); glVertex2f(0,py+h+graphSpacer/2.0);
glVertex2f(w,py+h+graphSpacer/2.0); glVertex2f(w,py+h+graphSpacer/2.0);
glColor4f(.3,.3,.3,1.0); glColor4f(.3,.3,.3,1.0);
glVertex2f(w,py+h+graphSpacer); glVertex2f(w,py+h+graphSpacer);
glVertex2f(0,py+h+graphSpacer); glVertex2f(0,py+h+graphSpacer);
glEnd(); glEnd();
//}
} }
py+=h; py=ceil(py+h+graphSpacer);
//if (i<numgraphs-1)
py+=graphSpacer;
py=ceil(py);
} }
if (!numgraphs) { if (!numgraphs) {
QColor col=Qt::black; QColor col=Qt::black;
@ -1275,10 +1263,10 @@ void gGraphView::paintGL()
AddTextQue(m_emptytext,(width()/2)-x/2,(height()/2)+y/2,0.0,col,bigfont); AddTextQue(m_emptytext,(width()/2)-x/2,(height()/2)+y/2,0.0,col,bigfont);
} }
if (threaded) { // if (threaded) {
masterlock->acquire(m_idealthreads); masterlock->acquire(m_idealthreads); // ask for all the CPU's back..
masterlock->release(m_idealthreads); masterlock->release(m_idealthreads);
} //}
for (int i=0;i<m_graphs.size();i++) { for (int i=0;i<m_graphs.size();i++) {
m_graphs[i]->drawGLBuf(); m_graphs[i]->drawGLBuf();

View File

@ -233,6 +233,8 @@ public:
gThread * thread() { return m_thread; } gThread * thread() { return m_thread; }
virtual void paint(int originX, int originY, int width, int height); virtual void paint(int originX, int originY, int width, int height);
void threadDone(); void threadDone();
bool threadRunning() { return m_thread->isRunning(); }
void threadStart() { if (!m_thread->isRunning()) m_thread->start(); }
protected: protected:
//void invalidate(); //void invalidate();
@ -311,7 +313,6 @@ public:
QMutex text_mutex; QMutex text_mutex;
QMutex gl_mutex; QMutex gl_mutex;
void setDay(Day * day); void setDay(Day * day);
void threadDone();
QSemaphore * masterlock; QSemaphore * masterlock;
bool useThreads() { return m_idealthreads>1; } bool useThreads() { return m_idealthreads>1; }
protected: protected:

View File

@ -32,9 +32,6 @@ gLineChart::~gLineChart()
// Time Domain Line Chart // Time Domain Line Chart
void gLineChart::paint(gGraph & w,int left, int top, int width, int height) void gLineChart::paint(gGraph & w,int left, int top, int width, int height)
{ {
const int max_drawlist_size=4096;
QPoint m_drawlist[max_drawlist_size];
if (!m_visible) if (!m_visible)
return; return;

View File

@ -34,6 +34,9 @@ protected:
QColor m_line_color; QColor m_line_color;
GLBuffer * lines; GLBuffer * lines;
GLBuffer * outlines; GLBuffer * outlines;
static const int max_drawlist_size=4096;
QPoint m_drawlist[max_drawlist_size];
}; };
#endif // GLINECHART_H #endif // GLINECHART_H

View File

@ -11,10 +11,10 @@
gLineOverlayBar::gLineOverlayBar(ChannelID code,QColor color,QString label,FlagType flt) gLineOverlayBar::gLineOverlayBar(ChannelID code,QColor color,QString label,FlagType flt)
:Layer(code),m_flag_color(color),m_label(label),m_flt(flt) :Layer(code),m_flag_color(color),m_label(label),m_flt(flt)
{ {
addGLBuf(points=new GLBuffer(color,2048,GL_POINTS)); addGLBuf(points=new GLBuffer(color,1024,GL_POINTS));
points->setSize(4); points->setSize(4);
addGLBuf(quads=new GLBuffer(color,2048,GL_QUADS)); addGLBuf(quads=new GLBuffer(color,2048,GL_QUADS));
addGLBuf(lines=new GLBuffer(color,2048,GL_LINES)); addGLBuf(lines=new GLBuffer(color,1024,GL_LINES));
points->setAntiAlias(true); points->setAntiAlias(true);
quads->setAntiAlias(true); quads->setAntiAlias(true);
lines->setAntiAlias(true); lines->setAntiAlias(true);
@ -41,21 +41,6 @@ void gLineOverlayBar::paint(gGraph & w, int left, int topp, int width, int heigh
int x,y; int x,y;
// Crop to inside the margins.
// glScissor(left,topp,width,height);
// glEnable(GL_SCISSOR_TEST);
/*qint32 vertcnt=0;
GLshort * vertarray=vertex_array[0];
qint32 pointcnt=0;
GLshort * pointarray=vertex_array[1];
qint32 quadcnt=0;
GLshort * quadarray=vertex_array[2];
if (!vertarray || !quadarray || !pointarray) {
qWarning() << "VertArray/quadarray/pointarray==NULL";
return;
}*/
float bottom=start_py+height-25, top=start_py+25; float bottom=start_py+height-25, top=start_py+25;
double X; double X;
@ -95,9 +80,7 @@ void gLineOverlayBar::paint(gGraph & w, int left, int topp, int width, int heigh
quads->add(x2,start_py+height,x1,start_py+height); quads->add(x2,start_py+height,x1,start_py+height);
if (quads->full()) { verts_exceeded=true; break; } if (quads->full()) { verts_exceeded=true; break; }
} else if (m_flt==FT_Dot) { } else if (m_flt==FT_Dot) {
//if (pref["AlwaysShowOverlayBars"].toBool()) { if (pref["AlwaysShowOverlayBars"].toBool() || (xx<3600000)) {
if (pref["AlwaysShowOverlayBars"].toBool() || (xx<3600000.0)) {
// show the fat dots in the middle // show the fat dots in the middle
points->add(x1,double(height)/double(yy)*double(-20-w.min_y)+topp); points->add(x1,double(height)/double(yy)*double(-20-w.min_y)+topp);
if (points->full()) { verts_exceeded=true; break; } if (points->full()) { verts_exceeded=true; break; }
@ -134,24 +117,5 @@ void gLineOverlayBar::paint(gGraph & w, int left, int topp, int width, int heigh
if (verts_exceeded) { if (verts_exceeded) {
qWarning() << "exceeded maxverts in gLineOverlay::Plot()"; qWarning() << "exceeded maxverts in gLineOverlay::Plot()";
} }
/* bool antialias=pref["UseAntiAliasing"].toBool();
if (antialias) {
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); //_MINUS_SRC_ALPHA);
glEnable(GL_LINE_SMOOTH);
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
glLineWidth (1.5);
} else glLineWidth (1);
//quads->draw();
//lines->draw();
//points->draw();
if (antialias) {
glDisable(GL_LINE_SMOOTH);
glDisable(GL_BLEND);
} */
//glDisable(GL_SCISSOR_TEST);
} }