ThreadWeaver

executewrapper.cpp
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
11namespace ThreadWeaver
12{
13ExecuteWrapper::ExecuteWrapper()
14{
15}
16
17ExecuteWrapper::~ExecuteWrapper()
18{
19 auto wrapped = this->wrapped.loadAcquire();
20 if (wrapped && wrapped->ownedByJob())
21 delete wrapped;
22}
23
24Executor *ExecuteWrapper::wrap(Executor *previous)
25{
26 return wrapped.fetchAndStoreOrdered(previous);
27}
28
29Executor *ExecuteWrapper::unwrap(JobInterface *job)
30{
31 Executor *executor = job->setExecutor(wrapped.fetchAndStoreOrdered(nullptr));
32 Q_ASSERT_X(executor == this, Q_FUNC_INFO, "ExecuteWrapper can only unwrap itself!");
33 return executor;
34}
35
36void ExecuteWrapper::begin(const JobPointer &job, Thread *thread)
37{
38 Q_ASSERT(wrapped.loadAcquire() != nullptr);
39 wrapped.loadAcquire()->begin(job, thread);
40}
41
42void ExecuteWrapper::execute(const JobPointer &job, Thread *thread)
43{
44 executeWrapped(job, thread);
45}
46
47void 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
54void 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"
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:58:06 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.