Much more correct work with QThreadPool.
Use "volatile" keyword. Don't use method waitForDone() anymore. --HG-- branch : develop
This commit is contained in:
parent
84661014e8
commit
44ef0936d9
|
@ -91,7 +91,7 @@ private:
|
||||||
VBank *bank;
|
VBank *bank;
|
||||||
int paperHeight;
|
int paperHeight;
|
||||||
int paperWidth;
|
int paperWidth;
|
||||||
bool stopGeneration;
|
volatile bool stopGeneration;
|
||||||
LayoutErrors state;
|
LayoutErrors state;
|
||||||
unsigned int shift;
|
unsigned int shift;
|
||||||
bool rotate;
|
bool rotate;
|
||||||
|
|
|
@ -154,7 +154,7 @@ void VLayoutPaper::SetPaperIndex(quint32 index)
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
bool VLayoutPaper::ArrangeDetail(const VLayoutDetail &detail, bool &stop)
|
bool VLayoutPaper::ArrangeDetail(const VLayoutDetail &detail, volatile bool &stop)
|
||||||
{
|
{
|
||||||
// First need set size of paper
|
// First need set size of paper
|
||||||
if (d->globalContour.GetHeight() <= 0 || d->globalContour.GetWidth() <= 0)
|
if (d->globalContour.GetHeight() <= 0 || d->globalContour.GetWidth() <= 0)
|
||||||
|
@ -179,15 +179,13 @@ int VLayoutPaper::Count() const
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
bool VLayoutPaper::AddToSheet(const VLayoutDetail &detail, bool &stop)
|
bool VLayoutPaper::AddToSheet(const VLayoutDetail &detail, volatile bool &stop)
|
||||||
{
|
{
|
||||||
VBestSquare bestResult;
|
VBestSquare bestResult;
|
||||||
QThreadPool *thread_pool = QThreadPool::globalInstance();
|
QThreadPool *thread_pool = QThreadPool::globalInstance();
|
||||||
thread_pool->setExpiryTimeout(1000);
|
thread_pool->setExpiryTimeout(1000);
|
||||||
QVector<VPosition *> threads;
|
QVector<VPosition *> threads;
|
||||||
|
|
||||||
QCoreApplication::processEvents();
|
|
||||||
|
|
||||||
for (int j=1; j <= d->globalContour.EdgesCount(); ++j)
|
for (int j=1; j <= d->globalContour.EdgesCount(); ++j)
|
||||||
{
|
{
|
||||||
for (int i=1; i<= detail.EdgesCount(); i++)
|
for (int i=1; i<= detail.EdgesCount(); i++)
|
||||||
|
@ -209,9 +207,13 @@ bool VLayoutPaper::AddToSheet(const VLayoutDetail &detail, bool &stop)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
thread_pool->waitForDone();
|
// Wait for done
|
||||||
|
do
|
||||||
QCoreApplication::processEvents();
|
{
|
||||||
|
QCoreApplication::processEvents();
|
||||||
|
QThread::msleep(250);
|
||||||
|
}
|
||||||
|
while(thread_pool->activeThreadCount() > 0 && not stop);
|
||||||
|
|
||||||
if (stop)
|
if (stop)
|
||||||
{
|
{
|
||||||
|
|
|
@ -67,7 +67,7 @@ public:
|
||||||
|
|
||||||
void SetPaperIndex(quint32 index);
|
void SetPaperIndex(quint32 index);
|
||||||
|
|
||||||
bool ArrangeDetail(const VLayoutDetail &detail, bool &stop);
|
bool ArrangeDetail(const VLayoutDetail &detail, volatile bool &stop);
|
||||||
int Count() const;
|
int Count() const;
|
||||||
QGraphicsRectItem *GetPaperItem(bool autoCrop) const;
|
QGraphicsRectItem *GetPaperItem(bool autoCrop) const;
|
||||||
QList<QGraphicsItem *> GetDetails() const;
|
QList<QGraphicsItem *> GetDetails() const;
|
||||||
|
@ -75,7 +75,7 @@ public:
|
||||||
private:
|
private:
|
||||||
QSharedDataPointer<VLayoutPaperData> d;
|
QSharedDataPointer<VLayoutPaperData> d;
|
||||||
|
|
||||||
bool AddToSheet(const VLayoutDetail &detail, bool &stop);
|
bool AddToSheet(const VLayoutDetail &detail, volatile bool &stop);
|
||||||
|
|
||||||
bool SaveResult(const VBestSquare &bestResult, const VLayoutDetail &detail);
|
bool SaveResult(const VBestSquare &bestResult, const VLayoutDetail &detail);
|
||||||
|
|
||||||
|
|
|
@ -46,8 +46,8 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
VPosition::VPosition(const VContour &gContour, int j, const VLayoutDetail &detail, int i, bool *stop, bool rotate,
|
VPosition::VPosition(const VContour &gContour, int j, const VLayoutDetail &detail, int i, volatile bool *stop,
|
||||||
int rotationIncrease)
|
bool rotate, int rotationIncrease)
|
||||||
:QRunnable(), bestResult(VBestSquare()), gContour(gContour), detail(detail), i(i), j(j), paperIndex(0), frame(0),
|
:QRunnable(), bestResult(VBestSquare()), gContour(gContour), detail(detail), i(i), j(j), paperIndex(0), frame(0),
|
||||||
detailsCount(0), details(QVector<VLayoutDetail>()), stop(stop), rotate(rotate), rotationIncrease(rotationIncrease)
|
detailsCount(0), details(QVector<VLayoutDetail>()), stop(stop), rotate(rotate), rotationIncrease(rotationIncrease)
|
||||||
{
|
{
|
||||||
|
@ -65,8 +65,6 @@ void VPosition::run()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QCoreApplication::processEvents();
|
|
||||||
|
|
||||||
// We should use copy of the detail.
|
// We should use copy of the detail.
|
||||||
VLayoutDetail workDetail = detail;
|
VLayoutDetail workDetail = detail;
|
||||||
|
|
||||||
|
@ -654,8 +652,6 @@ void VPosition::Rotate(int increase)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QCoreApplication::processEvents();
|
|
||||||
|
|
||||||
// We should use copy of the detail.
|
// We should use copy of the detail.
|
||||||
VLayoutDetail workDetail = detail;
|
VLayoutDetail workDetail = detail;
|
||||||
|
|
||||||
|
|
|
@ -46,12 +46,10 @@ class QPainterPath;
|
||||||
class VPosition : public QRunnable
|
class VPosition : public QRunnable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
VPosition(const VContour &gContour, int j, const VLayoutDetail &detail, int i, bool *stop, bool rotate,
|
VPosition(const VContour &gContour, int j, const VLayoutDetail &detail, int i, volatile bool *stop, bool rotate,
|
||||||
int rotationIncrease);
|
int rotationIncrease);
|
||||||
virtual ~VPosition(){}
|
virtual ~VPosition(){}
|
||||||
|
|
||||||
virtual void run();
|
|
||||||
|
|
||||||
quint32 getPaperIndex() const;
|
quint32 getPaperIndex() const;
|
||||||
void setPaperIndex(const quint32 &value);
|
void setPaperIndex(const quint32 &value);
|
||||||
|
|
||||||
|
@ -81,7 +79,7 @@ private:
|
||||||
quint32 frame;
|
quint32 frame;
|
||||||
quint32 detailsCount;
|
quint32 detailsCount;
|
||||||
QVector<VLayoutDetail> details;
|
QVector<VLayoutDetail> details;
|
||||||
bool *stop;
|
volatile bool *stop;
|
||||||
bool rotate;
|
bool rotate;
|
||||||
int rotationIncrease;
|
int rotationIncrease;
|
||||||
|
|
||||||
|
@ -99,6 +97,8 @@ private:
|
||||||
EdgeError = 2
|
EdgeError = 2
|
||||||
};
|
};
|
||||||
|
|
||||||
|
virtual void run();
|
||||||
|
|
||||||
void SaveCandidate(VBestSquare &bestResult, const VLayoutDetail &detail, int globalI, int detJ, BestFrom type);
|
void SaveCandidate(VBestSquare &bestResult, const VLayoutDetail &detail, int globalI, int detJ, BestFrom type);
|
||||||
|
|
||||||
bool CheckCombineEdges(VLayoutDetail &detail, int j, int &dEdge) const;
|
bool CheckCombineEdges(VLayoutDetail &detail, int j, int &dEdge) const;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user