diff options
author | Tor Lillqvist <tml@collabora.com> | 2013-11-08 10:16:39 +0200 |
---|---|---|
committer | Michael Meeks <michael.meeks@collabora.com> | 2013-11-20 18:23:03 +0000 |
commit | 723060d4b301e80bf6390422a0e82d56ab8e1fd3 (patch) | |
tree | 15286ea07b9ee42289c0ca8fddc8c31fcc0a9f55 /sc/source/core/data | |
parent | 89f8829a62479c6d6deb1ffaab1baf710c8cc856 (diff) |
WIP: Do OpenCL compilation in advance in a worker thread
Change-Id: I9fbf848bd487e5ea49a383461f04e3c1678af607
Diffstat (limited to 'sc/source/core/data')
-rw-r--r-- | sc/source/core/data/formulacell.cxx | 42 |
1 files changed, 42 insertions, 0 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; } |