lmms
Cross-platform music production software
Toggle main menu visibility
Loading...
Searching...
No Matches
include
ThreadableJob.h
Go to the documentation of this file.
1
/*
2
* ThreadableJob.h - declaration of class ThreadableJob
3
*
4
* Copyright (c) 2009-2014 Tobias Doerffel <tobydox/at/users.sourceforge.net>
5
*
6
* This file is part of LMMS - https://lmms.io
7
*
8
* This program is free software; you can redistribute it and/or
9
* modify it under the terms of the GNU General Public
10
* License as published by the Free Software Foundation; either
11
* version 2 of the License, or (at your option) any later version.
12
*
13
* This program is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
* General Public License for more details.
17
*
18
* You should have received a copy of the GNU General Public
19
* License along with this program (see COPYING); if not, write to the
20
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21
* Boston, MA 02110-1301 USA.
22
*
23
*/
24
25
#ifndef LMMS_THREADABLE_JOB_H
26
#define LMMS_THREADABLE_JOB_H
27
28
#include "
LmmsTypes.h
"
29
30
#include <atomic>
31
32
namespace
lmms
33
{
34
35
class
ThreadableJob
36
{
37
public
:
38
39
enum class
ProcessingState
:
int
40
{
41
Unstarted,
42
Queued,
43
InProgress,
44
Done
45
};
46
47
ThreadableJob
() :
48
m_state
(
ProcessingState
::Unstarted)
49
{
50
}
51
52
inline
ProcessingState
state
()
const
53
{
54
return
m_state
.load();
55
}
56
57
inline
void
reset
()
58
{
59
m_state
=
ProcessingState::Unstarted
;
60
}
61
62
inline
void
queue
()
63
{
64
m_state
=
ProcessingState::Queued
;
65
}
66
67
inline
void
done
()
68
{
69
m_state
=
ProcessingState::Done
;
70
}
71
72
void
process
()
73
{
74
auto
expected =
ProcessingState::Queued
;
75
if
(
m_state
.compare_exchange_strong(expected,
ProcessingState::InProgress
))
76
{
77
doProcessing
();
78
m_state
=
ProcessingState::Done
;
79
}
80
}
81
82
virtual
bool
requiresProcessing
()
const
= 0;
83
84
85
protected
:
86
virtual
void
doProcessing
() = 0;
87
88
std::atomic<ProcessingState>
m_state
;
89
} ;
90
91
}
// namespace lmms
92
93
#endif
// LMMS_THREADABLE_JOB_H
LmmsTypes.h
lmms::ThreadableJob::done
void done()
Definition
ThreadableJob.h:67
lmms::ThreadableJob::m_state
std::atomic< ProcessingState > m_state
Definition
ThreadableJob.h:88
lmms::ThreadableJob::doProcessing
virtual void doProcessing()=0
lmms::ThreadableJob::requiresProcessing
virtual bool requiresProcessing() const =0
lmms::ThreadableJob::reset
void reset()
Definition
ThreadableJob.h:57
lmms::ThreadableJob::queue
void queue()
Definition
ThreadableJob.h:62
lmms::ThreadableJob::state
ProcessingState state() const
Definition
ThreadableJob.h:52
lmms::ThreadableJob::ThreadableJob
ThreadableJob()
Definition
ThreadableJob.h:47
lmms::ThreadableJob::ProcessingState
ProcessingState
Definition
ThreadableJob.h:40
lmms::ThreadableJob::ProcessingState::InProgress
@ InProgress
Definition
ThreadableJob.h:43
lmms::ThreadableJob::ProcessingState::Queued
@ Queued
Definition
ThreadableJob.h:42
lmms::ThreadableJob::ProcessingState::Unstarted
@ Unstarted
Definition
ThreadableJob.h:41
lmms::ThreadableJob::ProcessingState::Done
@ Done
Definition
ThreadableJob.h:44
lmms::ThreadableJob::process
void process()
Definition
ThreadableJob.h:72
lmms
Definition
RemotePluginBase.cpp:34
Generated on
for lmms by
1.18.0