File indexing completed on 2024-04-28 04:01:23
0001 /* -*- C++ -*- 0002 This file is part of ThreadWeaver. 0003 0004 SPDX-FileCopyrightText: 2005-2013 Mirko Boehm <mirko@kde.org> 0005 0006 SPDX-License-Identifier: LGPL-2.0-or-later 0007 */ 0008 0009 #include "job_p.h" 0010 #include "debuggingaids.h" 0011 #include "executor_p.h" 0012 #include "queuepolicy.h" 0013 #include "thread.h" 0014 0015 ThreadWeaver::Private::DefaultExecutor ThreadWeaver::Private::defaultExecutor; 0016 0017 ThreadWeaver::Private::Job_Private::Job_Private() 0018 : status(Job::Status_NoStatus) 0019 , shouldAbort(false) 0020 , executor(&defaultExecutor) 0021 { 0022 } 0023 0024 ThreadWeaver::Private::Job_Private::~Job_Private() 0025 { 0026 auto executor = this->executor.loadAcquire(); 0027 if (executor->ownedByJob()) 0028 delete executor; 0029 } 0030 0031 void ThreadWeaver::Private::Job_Private::freeQueuePolicyResources(JobPointer job) 0032 { 0033 for (int index = 0; index < queuePolicies.size(); ++index) { 0034 queuePolicies.at(index)->free(job); 0035 } 0036 } 0037 0038 void ThreadWeaver::Private::Job_Private::handleFinish(const JobPointer &job) 0039 { 0040 QMutexLocker l(&mutex); 0041 QList<std::function<void(const JobInterface &job)>> handlers = finishHandlers; 0042 // We need to unlock mutex because 0043 // handlers might want to use Job methods that also need this same mutex 0044 l.unlock(); 0045 for (auto handler : handlers) { 0046 handler(*job.get()); 0047 } 0048 } 0049 0050 void ThreadWeaver::Private::DebugExecuteWrapper::execute(const JobPointer &job, ThreadWeaver::Thread *th) 0051 { 0052 Q_ASSERT_X(job, Q_FUNC_INFO, "job may not be zero!"); 0053 TWDEBUG(3, "DefaultExecuteWrapper::execute: executing job %p in thread %i.\n", job.data(), th ? th->id() : 0); 0054 executeWrapped(job, th); 0055 TWDEBUG(3, "Job::execute: finished execution of job in thread %i.\n", th ? th->id() : 0); 0056 } 0057 0058 void ThreadWeaver::Private::DefaultExecutor::begin(const JobPointer &job, Thread *thread) 0059 { 0060 defaultBegin(job, thread); 0061 } 0062 0063 void ThreadWeaver::Private::DefaultExecutor::execute(const JobPointer &job, Thread *thread) 0064 { 0065 run(job, thread); 0066 } 0067 0068 void ThreadWeaver::Private::DefaultExecutor::end(const JobPointer &job, Thread *thread) 0069 { 0070 defaultEnd(job, thread); 0071 }