| 1 | /* -*- C++ -*- |
| 2 | Class to manipulate job execution in 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 "executewrapper_p.h" |
| 10 | |
| 11 | namespace ThreadWeaver |
| 12 | { |
| 13 | ExecuteWrapper::ExecuteWrapper() |
| 14 | { |
| 15 | } |
| 16 | |
| 17 | ExecuteWrapper::~ExecuteWrapper() |
| 18 | { |
| 19 | auto wrapped = this->wrapped.loadAcquire(); |
| 20 | if (wrapped && wrapped->ownedByJob()) |
| 21 | delete wrapped; |
| 22 | } |
| 23 | |
| 24 | Executor *ExecuteWrapper::wrap(Executor *previous) |
| 25 | { |
| 26 | return wrapped.fetchAndStoreOrdered(newValue: previous); |
| 27 | } |
| 28 | |
| 29 | Executor *ExecuteWrapper::unwrap(JobInterface *job) |
| 30 | { |
| 31 | Executor *executor = job->setExecutor(wrapped.fetchAndStoreOrdered(newValue: nullptr)); |
| 32 | Q_ASSERT_X(executor == this, Q_FUNC_INFO, "ExecuteWrapper can only unwrap itself!" ); |
| 33 | return executor; |
| 34 | } |
| 35 | |
| 36 | void ExecuteWrapper::begin(const JobPointer &job, Thread *thread) |
| 37 | { |
| 38 | Q_ASSERT(wrapped.loadAcquire() != nullptr); |
| 39 | wrapped.loadAcquire()->begin(job, thread); |
| 40 | } |
| 41 | |
| 42 | void ExecuteWrapper::execute(const JobPointer &job, Thread *thread) |
| 43 | { |
| 44 | executeWrapped(job, thread); |
| 45 | } |
| 46 | |
| 47 | void ExecuteWrapper::executeWrapped(const JobPointer &job, Thread *thread) |
| 48 | { |
| 49 | Executor *executor = wrapped.loadAcquire(); |
| 50 | Q_ASSERT_X(executor != nullptr, Q_FUNC_INFO, "Wrapped Executor cannot be zero!" ); |
| 51 | executor->execute(job, thread); |
| 52 | } |
| 53 | |
| 54 | void ExecuteWrapper::end(const JobPointer &job, Thread *thread) |
| 55 | { |
| 56 | Q_ASSERT(wrapped.loadAcquire() != nullptr); |
| 57 | wrapped.loadAcquire()->end(job, thread); |
| 58 | } |
| 59 | |
| 60 | } |
| 61 | |
| 62 | #include "executewrapper_p.h" |
| 63 | |