LMMS
Loading...
Searching...
No Matches
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
32namespace lmms
33{
34
36{
37public:
38
46
51
52 inline ProcessingState state() const
53 {
54 return m_state.load();
55 }
56
57 inline void reset()
58 {
60 }
61
62 inline void queue()
63 {
65 }
66
67 inline void done()
68 {
70 }
71
72 void process()
73 {
74 auto expected = ProcessingState::Queued;
75 if (m_state.compare_exchange_strong(expected, ProcessingState::InProgress))
76 {
79 }
80 }
81
82 virtual bool requiresProcessing() const = 0;
83
84
85protected:
86 virtual void doProcessing() = 0;
87
88 std::atomic<ProcessingState> m_state;
89} ;
90
91} // namespace lmms
92
93#endif // LMMS_THREADABLE_JOB_H
void done()
Definition ThreadableJob.h:67
std::atomic< ProcessingState > m_state
Definition ThreadableJob.h:88
virtual void doProcessing()=0
virtual bool requiresProcessing() const =0
void reset()
Definition ThreadableJob.h:57
void queue()
Definition ThreadableJob.h:62
ProcessingState state() const
Definition ThreadableJob.h:52
ThreadableJob()
Definition ThreadableJob.h:47
ProcessingState
Definition ThreadableJob.h:40
@ InProgress
Definition ThreadableJob.h:43
@ Queued
Definition ThreadableJob.h:42
@ Unstarted
Definition ThreadableJob.h:41
@ Done
Definition ThreadableJob.h:44
void process()
Definition ThreadableJob.h:72
Definition AudioAlsa.cpp:35