1/* -*- C++ -*-
2 This file is part of ThreadWeaver.
3
4 SPDX-FileCopyrightText: 2005-2013 Mirko Boehm <mirko@kde.org>
5
6 SPDX-License-Identifier: LGPL-2.0-or-later
7*/
8
9#include "job_p.h"
10#include "debuggingaids.h"
11#include "executor_p.h"
12#include "queuepolicy.h"
13#include "thread.h"
14
15ThreadWeaver::Private::DefaultExecutor ThreadWeaver::Private::defaultExecutor;
16
17ThreadWeaver::Private::Job_Private::Job_Private()
18 : status(Job::Status_NoStatus)
19 , shouldAbort(false)
20 , executor(&defaultExecutor)
21{
22}
23
24ThreadWeaver::Private::Job_Private::~Job_Private()
25{
26 auto executor = this->executor.loadAcquire();
27 if (executor->ownedByJob())
28 delete executor;
29}
30
31void ThreadWeaver::Private::Job_Private::freeQueuePolicyResources(JobPointer job)
32{
33 for (int index = 0; index < queuePolicies.size(); ++index) {
34 queuePolicies.at(i: index)->free(job);
35 }
36}
37
38void ThreadWeaver::Private::Job_Private::handleFinish(const JobPointer &job)
39{
40 QMutexLocker l(&mutex);
41 QList<std::function<void(const JobInterface &job)>> handlers = finishHandlers;
42 // We need to unlock mutex because
43 // handlers might want to use Job methods that also need this same mutex
44 l.unlock();
45 for (auto handler : handlers) {
46 handler(*job.get());
47 }
48}
49
50void ThreadWeaver::Private::DebugExecuteWrapper::execute(const JobPointer &job, ThreadWeaver::Thread *th)
51{
52 Q_ASSERT_X(job, Q_FUNC_INFO, "job may not be zero!");
53 TWDEBUG(3, "DefaultExecuteWrapper::execute: executing job %p in thread %i.\n", job.data(), th ? th->id() : 0);
54 executeWrapped(job, thread: th);
55 TWDEBUG(3, "Job::execute: finished execution of job in thread %i.\n", th ? th->id() : 0);
56}
57
58void ThreadWeaver::Private::DefaultExecutor::begin(const JobPointer &job, Thread *thread)
59{
60 defaultBegin(job, thread);
61}
62
63void ThreadWeaver::Private::DefaultExecutor::execute(const JobPointer &job, Thread *thread)
64{
65 run(job, thread);
66}
67
68void ThreadWeaver::Private::DefaultExecutor::end(const JobPointer &job, Thread *thread)
69{
70 defaultEnd(job, thread);
71}
72

source code of threadweaver/src/job_p.cpp