Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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 : */
9 :
10 : #include <sal/log.hxx>
11 :
12 : #include "formulagroup.hxx"
13 : #include "grouptokenconverter.hxx"
14 :
15 : #include "clkernelthread.hxx"
16 :
17 : using namespace std;
18 :
19 : namespace sc {
20 :
21 0 : CLBuildKernelThread::CLBuildKernelThread() :
22 0 : salhelper::Thread("opencl-build-kernel-thread")
23 : {
24 0 : }
25 :
26 0 : CLBuildKernelThread::~CLBuildKernelThread()
27 : {
28 0 : }
29 :
30 0 : void CLBuildKernelThread::execute()
31 : {
32 : SAL_INFO("sc.opencl.thread", "running");
33 :
34 0 : bool done = false;
35 0 : while (!done)
36 : {
37 : SAL_INFO("sc.opencl.thread", "waiting for condition");
38 0 : maQueueCondition.wait();
39 : SAL_INFO("sc.opencl.thread", "got condition");
40 0 : osl::ResettableMutexGuard aGuard(maQueueMutex);
41 0 : maQueueCondition.reset();
42 0 : while (!maQueue.empty())
43 : {
44 0 : CLBuildKernelWorkItem aWorkItem = maQueue.front();
45 0 : maQueue.pop();
46 0 : aGuard.clear();
47 :
48 0 : switch (aWorkItem.meWhatToDo)
49 : {
50 : case CLBuildKernelWorkItem::COMPILE:
51 : SAL_INFO("sc.opencl.thread", "told to compile group " << aWorkItem.mxGroup << " (state " << aWorkItem.mxGroup->meCalcState << ") to binary");
52 0 : aWorkItem.mxGroup->compileOpenCLKernel();
53 : SAL_INFO("sc.opencl.thread", "group " << aWorkItem.mxGroup << " compilation done");
54 0 : maCompilationDoneCondition.set();
55 0 : break;
56 : case CLBuildKernelWorkItem::FINISH:
57 : SAL_INFO("sc.opencl.thread", "told to finish");
58 0 : done = true;
59 0 : break;
60 : }
61 :
62 0 : aGuard.reset();
63 0 : }
64 0 : }
65 0 : }
66 :
67 0 : void CLBuildKernelThread::push(CLBuildKernelWorkItem item)
68 : {
69 0 : osl::MutexGuard guard(maQueueMutex);
70 0 : maQueue.push(item);
71 0 : maQueueCondition.set();
72 :
73 : // This is only to ensure that the OpenCL parameters are initialized on
74 : // the main thread before spawning a worker thread for kernel
75 : // pre-compilation.
76 0 : sc::FormulaGroupInterpreter::getStatic();
77 0 : }
78 :
79 0 : void CLBuildKernelThread::produce()
80 : {
81 0 : }
82 :
83 0 : void CLBuildKernelThread::consume()
84 : {
85 0 : }
86 :
87 0 : void CLBuildKernelThread::finish()
88 : {
89 : SAL_INFO("sc.opencl", "telling thread to finish");
90 0 : CLBuildKernelWorkItem aWorkItem;
91 0 : aWorkItem.meWhatToDo = CLBuildKernelWorkItem::FINISH;
92 0 : push(aWorkItem);
93 0 : }
94 :
95 : }
96 :
97 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|