File indexing completed on 2024-04-28 15:34:51

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 Executor *ExecuteWrapper::wrap(Executor *previous)
0018 {
0019     return wrapped.fetchAndStoreOrdered(previous);
0020 }
0021 
0022 Executor *ExecuteWrapper::unwrap(const JobPointer &job)
0023 {
0024     Executor *executor = job->setExecutor(wrapped.fetchAndStoreOrdered(nullptr));
0025     Q_ASSERT_X(executor == this, Q_FUNC_INFO, "ExecuteWrapper can only unwrap itself!");
0026     return executor;
0027 }
0028 
0029 void ExecuteWrapper::begin(const JobPointer &job, Thread *thread)
0030 {
0031     Q_ASSERT(wrapped.loadAcquire() != nullptr);
0032     wrapped.loadAcquire()->begin(job, thread);
0033 }
0034 
0035 void ExecuteWrapper::execute(const JobPointer &job, Thread *thread)
0036 {
0037     executeWrapped(job, thread);
0038 }
0039 
0040 void ExecuteWrapper::executeWrapped(const JobPointer &job, Thread *thread)
0041 {
0042     Executor *executor = wrapped.loadAcquire();
0043     Q_ASSERT_X(executor != nullptr, Q_FUNC_INFO, "Wrapped Executor cannot be zero!");
0044     executor->execute(job, thread);
0045 }
0046 
0047 void ExecuteWrapper::end(const JobPointer &job, Thread *thread)
0048 {
0049     Q_ASSERT(wrapped.loadAcquire() != nullptr);
0050     wrapped.loadAcquire()->end(job, thread);
0051 }
0052 
0053 }
0054 
0055 #include "executewrapper_p.h"