1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 #include <sal/log.hxx>
12 #include "formulagroup.hxx"
13 #include "grouptokenconverter.hxx"
15 #include "clkernelthread.hxx"
21 CLBuildKernelThread::CLBuildKernelThread() :
22 salhelper::Thread("opencl-build-kernel-thread")
26 CLBuildKernelThread::~CLBuildKernelThread()
30 void CLBuildKernelThread::execute()
32 SAL_INFO("sc.opencl.thread", "running");
37 SAL_INFO("sc.opencl.thread", "waiting for condition");
38 maQueueCondition
.wait();
39 SAL_INFO("sc.opencl.thread", "got condition");
40 osl::ResettableMutexGuard
aGuard(maQueueMutex
);
41 maQueueCondition
.reset();
42 while (!maQueue
.empty())
44 CLBuildKernelWorkItem aWorkItem
= maQueue
.front();
48 switch (aWorkItem
.meWhatToDo
)
50 case CLBuildKernelWorkItem::COMPILE
:
51 SAL_INFO("sc.opencl.thread", "told to compile group " << aWorkItem
.mxGroup
<< " (state " << aWorkItem
.mxGroup
->meCalcState
<< ") to binary");
52 aWorkItem
.mxGroup
->compileOpenCLKernel();
53 SAL_INFO("sc.opencl.thread", "group " << aWorkItem
.mxGroup
<< " compilation done");
54 maCompilationDoneCondition
.set();
56 case CLBuildKernelWorkItem::FINISH
:
57 SAL_INFO("sc.opencl.thread", "told to finish");
67 void CLBuildKernelThread::push(CLBuildKernelWorkItem item
)
69 osl::MutexGuard
guard(maQueueMutex
);
71 maQueueCondition
.set();
73 // This is only to ensure that the OpenCL parameters are initialized on
74 // the main thread before spawning a worker thread for kernel
76 sc::FormulaGroupInterpreter::getStatic();
79 void CLBuildKernelThread::produce()
83 void CLBuildKernelThread::consume()
87 void CLBuildKernelThread::finish()
89 SAL_INFO("sc.opencl", "telling thread to finish");
90 CLBuildKernelWorkItem aWorkItem
;
91 aWorkItem
.meWhatToDo
= CLBuildKernelWorkItem::FINISH
;
97 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */