Stop leaking all ScPostIt instances.
[LibreOffice.git] / sc / source / core / tool / clkernelthread.cxx
blob2a619c5cdbadf7a29babf49cf77bef3b0b8098d2
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
8 */
10 #include <sal/log.hxx>
12 #include "formulagroup.hxx"
13 #include "grouptokenconverter.hxx"
15 #include "clkernelthread.hxx"
17 using namespace std;
19 namespace sc {
21 CLBuildKernelThread::CLBuildKernelThread() :
22 salhelper::Thread("opencl-build-kernel-thread")
26 CLBuildKernelThread::~CLBuildKernelThread()
30 void CLBuildKernelThread::execute()
32 SAL_INFO("sc.opencl.thread", "running");
34 bool done = false;
35 while (!done)
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();
45 maQueue.pop();
46 aGuard.clear();
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 if (aWorkItem.mxGroup->meCalcState == sc::GroupCalcDisabled)
53 break;
54 assert(aWorkItem.mxGroup->meCalcState == sc::GroupCalcOpenCLKernelCompilationScheduled);
55 aWorkItem.mxGroup->mpCompiledFormula =
56 sc::FormulaGroupInterpreter::getStatic()->createCompiledFormula(*aWorkItem.mxGroup->mpTopCell->GetDocument(),
57 aWorkItem.mxGroup->mpTopCell->aPos,
58 aWorkItem.mxGroup,
59 *aWorkItem.mxGroup->mpCode);
60 aWorkItem.mxGroup->meCalcState = sc::GroupCalcOpenCLKernelBinaryCreated;
61 SAL_INFO("sc.opencl.thread", "group " << aWorkItem.mxGroup << " compilation done");
62 maCompilationDoneCondition.set();
63 break;
64 case CLBuildKernelWorkItem::FINISH:
65 SAL_INFO("sc.opencl.thread", "told to finish");
66 done = true;
67 break;
70 aGuard.reset();
75 void CLBuildKernelThread::push(CLBuildKernelWorkItem item)
77 osl::MutexGuard guard(maQueueMutex);
78 maQueue.push(item);
79 maQueueCondition.set();
82 void CLBuildKernelThread::produce()
86 void CLBuildKernelThread::consume()
90 void CLBuildKernelThread::finish()
92 SAL_INFO("sc.opencl", "telling thread to finish");
93 CLBuildKernelWorkItem aWorkItem;
94 aWorkItem.meWhatToDo = CLBuildKernelWorkItem::FINISH;
95 push(aWorkItem);
100 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */