File indexing completed on 2024-04-28 04:01:22

0001 /* -*- C++ -*-
0002     Class to manipulate job execution in 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 "executewrapper_p.h"
0010 
0011 namespace ThreadWeaver
0012 {
0013 ExecuteWrapper::ExecuteWrapper()
0014 {
0015 }
0016 
0017 ExecuteWrapper::~ExecuteWrapper()
0018 {
0019     auto wrapped = this->wrapped.loadAcquire();
0020     if (wrapped && wrapped->ownedByJob())
0021         delete wrapped;
0022 }
0023 
0024 Executor *ExecuteWrapper::wrap(Executor *previous)
0025 {
0026     return wrapped.fetchAndStoreOrdered(previous);
0027 }
0028 
0029 Executor *ExecuteWrapper::unwrap(JobInterface *job)
0030 {
0031     Executor *executor = job->setExecutor(wrapped.fetchAndStoreOrdered(nullptr));
0032     Q_ASSERT_X(executor == this, Q_FUNC_INFO, "ExecuteWrapper can only unwrap itself!");
0033     return executor;
0034 }
0035 
0036 void ExecuteWrapper::begin(const JobPointer &job, Thread *thread)
0037 {
0038     Q_ASSERT(wrapped.loadAcquire() != nullptr);
0039     wrapped.loadAcquire()->begin(job, thread);
0040 }
0041 
0042 void ExecuteWrapper::execute(const JobPointer &job, Thread *thread)
0043 {
0044     executeWrapped(job, thread);
0045 }
0046 
0047 void ExecuteWrapper::executeWrapped(const JobPointer &job, Thread *thread)
0048 {
0049     Executor *executor = wrapped.loadAcquire();
0050     Q_ASSERT_X(executor != nullptr, Q_FUNC_INFO, "Wrapped Executor cannot be zero!");
0051     executor->execute(job, thread);
0052 }
0053 
0054 void ExecuteWrapper::end(const JobPointer &job, Thread *thread)
0055 {
0056     Q_ASSERT(wrapped.loadAcquire() != nullptr);
0057     wrapped.loadAcquire()->end(job, thread);
0058 }
0059 
0060 }
0061 
0062 #include "executewrapper_p.h"