chart2/source/view/charttypes/GL3DBarChart.cxx | 43 ++++++++++++++++++++----- chart2/source/view/inc/GL3DBarChart.hxx | 10 +++++ 2 files changed, 45 insertions(+), 8 deletions(-)
New commits: commit c73c54b8d6f33289e7a0f97436f40dce92a306bf Author: Markus Mohrhard <markus.mohrh...@collabora.co.uk> Date: Thu Aug 28 21:57:44 2014 +0200 replace sleep with two condition variables Change-Id: I7611b5be7d462646a19ebfd86b8d6612dccafc71 diff --git a/chart2/source/view/charttypes/GL3DBarChart.cxx b/chart2/source/view/charttypes/GL3DBarChart.cxx index 11406bf..d199b50 100644 --- a/chart2/source/view/charttypes/GL3DBarChart.cxx +++ b/chart2/source/view/charttypes/GL3DBarChart.cxx @@ -79,6 +79,27 @@ double findMaxValue(const boost::ptr_vector<VDataSeries>& rDataSeriesContainer) return nMax; } +class SharedResourceAccess +{ +private: + osl::Condition& mrCond1; + osl::Condition& mrCond2; + +public: + + SharedResourceAccess(osl::Condition& rCond1, osl::Condition& rCond2): + mrCond1(rCond1), + mrCond2(rCond2) + { + mrCond1.set(); + } + + ~SharedResourceAccess() + { + mrCond2.set(); + } +}; + } class RenderThread : public salhelper::Thread @@ -418,6 +439,7 @@ void RenderBenchMarkThread::execute() { { osl::MutexGuard aGuard(mpChart->maMutex); + mpChart->maCond2.reset(); if (mpChart->mbRenderDie) break; UpdateScreenText(); @@ -425,14 +447,11 @@ void RenderBenchMarkThread::execute() renderFrame(); mpChart->miFrameCount++; } - #ifdef WNT - Sleep(1); - #else - TimeValue nTV; - nTV.Seconds = 0; - nTV.Nanosec = 1000000; - osl_waitThread(&nTV); - #endif + if (mpChart->maCond1.check()) + { + mpChart->maCond1.reset(); + mpChart->maCond2.wait(); + } } } @@ -517,6 +536,7 @@ GL3DBarChart::~GL3DBarChart() { if (mbBenchMarkMode) { + SharedResourceAccess(maCond1, maCond2); osl::MutexGuard aGuard(maMutex); mbRenderDie = true; } @@ -531,6 +551,7 @@ GL3DBarChart::~GL3DBarChart() void GL3DBarChart::create3DShapes(const boost::ptr_vector<VDataSeries>& rDataSeriesContainer, ExplicitCategoriesProvider& rCatProvider) { + SharedResourceAccess(maCond1, maCond2); osl::MutexGuard aGuard(maMutex); mpRenderer->ReleaseShapes(); // Each series of data flows from left to right, and multiple series are @@ -803,6 +824,7 @@ void GL3DBarChart::moveToDefault() return; { + SharedResourceAccess(maCond1, maCond2); osl::MutexGuard aGuard(maMutex); maRenderEvent = EVENT_MOVE_TO_DEFAULT; } @@ -845,6 +867,7 @@ void GL3DBarChart::clickedAt(const Point& rPos, sal_uInt16 nButtons) return; { + SharedResourceAccess(maCond1, maCond2); osl::MutexGuard aGuard(maMutex); maClickPos = rPos; mnPreSelectBarId = mnSelectBarId; @@ -913,6 +936,7 @@ void GL3DBarChart::render() void GL3DBarChart::mouseDragMove(const Point& rStartPos, const Point& rEndPos, sal_uInt16 ) { long nDirection = rEndPos.X() - rStartPos.X(); + SharedResourceAccess(maCond1, maCond2); osl::MutexGuard aGuard(maMutex); if ((maRenderEvent == EVENT_NONE) || (maRenderEvent == EVENT_SHOW_SCROLL) || (maRenderEvent == EVENT_AUTO_FLY) || (maRenderEvent == EVENT_SHOW_SELECT)) @@ -989,6 +1013,7 @@ void GL3DBarChart::moveToCorner() void GL3DBarChart::scroll(long nDelta) { { + SharedResourceAccess(maCond1, maCond2); osl::MutexGuard aGuard(maMutex); if ((maRenderEvent != EVENT_NONE) && (maRenderEvent != EVENT_SHOW_SCROLL) && (maRenderEvent != EVENT_AUTO_FLY) && (maRenderEvent == EVENT_SHOW_SELECT)) @@ -1009,6 +1034,7 @@ void GL3DBarChart::scroll(long nDelta) void GL3DBarChart::contextDestroyed() { + SharedResourceAccess(maCond1, maCond2); osl::MutexGuard aGuard(maMutex); mbValidContext = false; } @@ -1055,6 +1081,7 @@ int GL3DBarChart::calcTimeInterval(TimeValue &startTime, TimeValue &endTime) void GL3DBarChart::updateScreenText() { + SharedResourceAccess(maCond1, maCond2); osl::MutexGuard aGuard(maMutex); maScreenTextShapes.clear(); mpRenderer->ReleaseScreenTextShapes(); diff --git a/chart2/source/view/inc/GL3DBarChart.hxx b/chart2/source/view/inc/GL3DBarChart.hxx index 007b8ad..11d7eeb 100644 --- a/chart2/source/view/inc/GL3DBarChart.hxx +++ b/chart2/source/view/inc/GL3DBarChart.hxx @@ -181,6 +181,16 @@ private: int mnColorRate; bool mbBenchMarkMode; sal_uInt32 maHistoryCounter; + + + // these form a pair: + // main thread sets condition 1 and waits until it can take the mutex + // render thread checks condition 1 before taking the mutex and waits in case it + // is set until condition 2 is set + // + // only necessary for the benchmark mode + osl::Condition maCond1; + osl::Condition maCond2; }; } _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits