summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Lillqvist <tml@collabora.com>2013-11-08 10:16:39 +0200
committerMichael Meeks <michael.meeks@collabora.com>2013-11-20 18:23:03 +0000
commit723060d4b301e80bf6390422a0e82d56ab8e1fd3 (patch)
tree15286ea07b9ee42289c0ca8fddc8c31fcc0a9f55
parent89f8829a62479c6d6deb1ffaab1baf710c8cc856 (diff)
WIP: Do OpenCL compilation in advance in a worker thread
Change-Id: I9fbf848bd487e5ea49a383461f04e3c1678af607
-rw-r--r--sc/Library_sc.mk1
-rw-r--r--sc/Library_scfilt.mk1
-rw-r--r--sc/inc/clkernelthread.hxx (renamed from sc/source/filter/inc/clkernelthread.hxx)10
-rw-r--r--sc/inc/formulacell.hxx5
-rw-r--r--sc/source/core/data/formulacell.cxx42
-rw-r--r--sc/source/core/opencl/formulagroupcl.cxx2
-rw-r--r--sc/source/core/tool/clkernelthread.cxx (renamed from sc/source/filter/ftools/clkernelthread.cxx)27
7 files changed, 83 insertions, 5 deletions
diff --git a/sc/Library_sc.mk b/sc/Library_sc.mk
index c9f0b5fbcf1f..3d575872352a 100644
--- a/sc/Library_sc.mk
+++ b/sc/Library_sc.mk
@@ -195,6 +195,7 @@ $(eval $(call gb_Library_add_exception_objects,sc,\
sc/source/core/tool/chartpos \
sc/source/core/tool/chgtrack \
sc/source/core/tool/chgviset \
+ sc/source/core/tool/clkernelthread \
sc/source/core/tool/compare \
sc/source/core/tool/compiler \
sc/source/core/tool/consoli \
diff --git a/sc/Library_scfilt.mk b/sc/Library_scfilt.mk
index c23af3db58d6..499f87326295 100644
--- a/sc/Library_scfilt.mk
+++ b/sc/Library_scfilt.mk
@@ -128,7 +128,6 @@ $(eval $(call gb_Library_add_exception_objects,scfilt,\
sc/source/filter/excel/xltools \
sc/source/filter/excel/xltracer \
sc/source/filter/excel/xlview \
- sc/source/filter/ftools/clkernelthread \
sc/source/filter/ftools/fapihelper \
sc/source/filter/ftools/fprogressbar \
sc/source/filter/ftools/ftools \
diff --git a/sc/source/filter/inc/clkernelthread.hxx b/sc/inc/clkernelthread.hxx
index 32586e731bd8..c780c2852b9a 100644
--- a/sc/source/filter/inc/clkernelthread.hxx
+++ b/sc/inc/clkernelthread.hxx
@@ -7,7 +7,8 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
-#include "salhelper/thread.hxx"
+#include <osl/conditn.hxx>
+#include <salhelper/thread.hxx>
namespace sc {
@@ -17,8 +18,15 @@ public:
CLBuildKernelThread();
virtual ~CLBuildKernelThread();
+ void finish();
+
protected:
virtual void execute();
+
+private:
+ osl::Condition maConsumeCondition;
+ void produce();
+ void consume();
};
}
diff --git a/sc/inc/formulacell.hxx b/sc/inc/formulacell.hxx
index b32f25066ce5..c151e06a80c2 100644
--- a/sc/inc/formulacell.hxx
+++ b/sc/inc/formulacell.hxx
@@ -23,6 +23,7 @@
#include "formularesult.hxx"
#include "formula/tokenarray.hxx"
+#include <rtl/ref.hxx>
#include "svl/listener.hxx"
#include "types.hxx"
@@ -31,6 +32,7 @@
namespace sc {
+class CLBuildKernelThread;
class StartListeningContext;
class EndListeningContext;
struct RefUpdateContext;
@@ -69,6 +71,9 @@ struct SC_DLLPUBLIC ScFormulaCellGroup : boost::noncopyable
void setCode( const ScTokenArray& rCode );
void compileCode(
ScDocument& rDoc, const ScAddress& rPos, formula::FormulaGrammar::Grammar eGram );
+
+ static int mnCount;
+ static rtl::Reference<sc::CLBuildKernelThread> mxCLKernelThread;
};
inline void intrusive_ptr_add_ref(const ScFormulaCellGroup *p)
diff --git a/sc/source/core/data/formulacell.cxx b/sc/source/core/data/formulacell.cxx
index 7c48a00a073c..6663fa9305a5 100644
--- a/sc/source/core/data/formulacell.cxx
+++ b/sc/source/core/data/formulacell.cxx
@@ -38,6 +38,7 @@
#include "editutil.hxx"
#include "chgtrack.hxx"
#include "tokenarray.hxx"
+#include "clkernelthread.hxx"
#include "formula/errorcodes.hxx"
#include "formula/vectortoken.hxx"
@@ -382,6 +383,26 @@ void adjustDBRange(ScToken* pToken, ScDocument& rNewDoc, const ScDocument* pOldD
}
+// The mutex to synchronize access to the OpenCL compilation thread.
+static osl::Mutex& getOpenCLCompilationThreadMutex()
+{
+ static osl::Mutex* pMutex = NULL;
+ if( !pMutex )
+ {
+ osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() );
+ if( !pMutex )
+ {
+ static osl::Mutex aMutex;
+ pMutex = &aMutex;
+ }
+ }
+
+ return *pMutex;
+}
+
+int ScFormulaCellGroup::mnCount = 0;
+rtl::Reference<sc::CLBuildKernelThread> ScFormulaCellGroup::mxCLKernelThread;
+
ScFormulaCellGroup::ScFormulaCellGroup() :
mnRefCount(0),
mpCode(NULL),
@@ -393,10 +414,31 @@ ScFormulaCellGroup::ScFormulaCellGroup() :
mbSubTotal(false),
meCalcState(sc::GroupCalcEnabled)
{
+ if (ScInterpreter::GetGlobalConfig().mbOpenCLEnabled)
+ {
+ osl::MutexGuard aGuard(getOpenCLCompilationThreadMutex());
+ if (mnCount++ == 0)
+ {
+ assert(!mxCLKernelThread.is());
+ mxCLKernelThread.set(new sc::CLBuildKernelThread);
+ mxCLKernelThread->launch();
+ }
+ }
}
ScFormulaCellGroup::~ScFormulaCellGroup()
{
+ if (ScInterpreter::GetGlobalConfig().mbOpenCLEnabled)
+ {
+ osl::MutexGuard aGuard(getOpenCLCompilationThreadMutex());
+ if (--mnCount == 0)
+ {
+ assert(mxCLKernelThread.is());
+ mxCLKernelThread->finish();
+ mxCLKernelThread->join();
+ mxCLKernelThread.clear();
+ }
+ }
delete mpCode;
}
diff --git a/sc/source/core/opencl/formulagroupcl.cxx b/sc/source/core/opencl/formulagroupcl.cxx
index 4c44402b021a..e2a74609cb48 100644
--- a/sc/source/core/opencl/formulagroupcl.cxx
+++ b/sc/source/core/opencl/formulagroupcl.cxx
@@ -2652,7 +2652,7 @@ CompiledFormula* FormulaGroupInterpreterOpenCL::createCompiledFormula(ScDocument
const ScAddress& rTopPos,
ScTokenArray& rCode)
{
- return sc::opencl::DynamicKernel::create(rDoc, rTopPos, rCode);
+ return DynamicKernel::create(rDoc, rTopPos, rCode);
}
bool FormulaGroupInterpreterOpenCL::interpret( ScDocument& rDoc,
diff --git a/sc/source/filter/ftools/clkernelthread.cxx b/sc/source/core/tool/clkernelthread.cxx
index c307793c3b41..90edf8c8c940 100644
--- a/sc/source/filter/ftools/clkernelthread.cxx
+++ b/sc/source/core/tool/clkernelthread.cxx
@@ -7,18 +7,41 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
+#include <sal/log.hxx>
+
#include "clkernelthread.hxx"
using namespace std;
namespace sc {
-CLBuildKernelThread::CLBuildKernelThread() : salhelper::Thread("opencl-build-kernel-thread") {}
+CLBuildKernelThread::CLBuildKernelThread() :
+ salhelper::Thread("opencl-build-kernel-thread")
+{
+}
-CLBuildKernelThread::~CLBuildKernelThread() {}
+CLBuildKernelThread::~CLBuildKernelThread()
+{
+}
void CLBuildKernelThread::execute()
{
+ SAL_INFO("sc", "opencl-buildkernel-thread running");
+
+ SAL_INFO("sc", "opencl-buildkernel-thread finishing");
+}
+
+void CLBuildKernelThread::produce()
+{
+}
+
+void CLBuildKernelThread::consume()
+{
+}
+
+void CLBuildKernelThread::finish()
+{
+ SAL_INFO("sc", "opencl-buildkernel-thread request to finish");
}
}