summaryrefslogtreecommitdiff
path: root/sc/source
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 /sc/source
parent89f8829a62479c6d6deb1ffaab1baf710c8cc856 (diff)
WIP: Do OpenCL compilation in advance in a worker thread
Change-Id: I9fbf848bd487e5ea49a383461f04e3c1678af607
Diffstat (limited to 'sc/source')
-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
-rw-r--r--sc/source/filter/inc/clkernelthread.hxx26
4 files changed, 68 insertions, 29 deletions
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");
}
}
diff --git a/sc/source/filter/inc/clkernelthread.hxx b/sc/source/filter/inc/clkernelthread.hxx
deleted file mode 100644
index 32586e731bd8..000000000000
--- a/sc/source/filter/inc/clkernelthread.hxx
+++ /dev/null
@@ -1,26 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * This file is part of the LibreOffice project.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- */
-
-#include "salhelper/thread.hxx"
-
-namespace sc {
-
-class CLBuildKernelThread : public salhelper::Thread
-{
-public:
- CLBuildKernelThread();
- virtual ~CLBuildKernelThread();
-
-protected:
- virtual void execute();
-};
-
-}
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */