mirror of
https://github.com/LMMS/lmms.git
synced 2026-01-02 19:48:02 -05:00
* ThreadableJob: Move from AtomicInt to std::atomic This is the first in a series of commits that migrates away from AtomicInt towards the C++11 standard library types. This would allow the removal of AtomicInt and related Qt version-specific code. While we're at it, also make ProcessingState an `enum class` so that it's not implicitly convertible to integers. * LocklessAllocator: Switch from AtomicInt to std::atomic_int If it looks like some assignments around the Compare & Swap loops went missing, it's because compare_exchange_weak() updates the first argument to the current value when it fails (i.e., returns false). * BufferManager: Remove extra AtomicInt include * MixerWorkerThread: AtomicInt to std::atomic_int * NotePlayHandle: AtomicInt to std::atomic_int * Remove AtomicInt.h * Move from QAtomicPointer to std::atomic<T*> This removes some #ifdef trickery that was being used to get load-acquire and store-release from Qt5 and "plain" (presumably sequentially-consistent) loads and stores from Qt4.
89 lines
1.8 KiB
C++
89 lines
1.8 KiB
C++
/*
|
|
* ThreadableJob.h - declaration of class ThreadableJob
|
|
*
|
|
* Copyright (c) 2009-2014 Tobias Doerffel <tobydox/at/users.sourceforge.net>
|
|
*
|
|
* This file is part of LMMS - https://lmms.io
|
|
*
|
|
* This program is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU General Public
|
|
* License as published by the Free Software Foundation; either
|
|
* version 2 of the License, or (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
* General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public
|
|
* License along with this program (see COPYING); if not, write to the
|
|
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
* Boston, MA 02110-1301 USA.
|
|
*
|
|
*/
|
|
|
|
#ifndef THREADABLE_JOB_H
|
|
#define THREADABLE_JOB_H
|
|
|
|
#include "lmms_basics.h"
|
|
|
|
#include <atomic>
|
|
|
|
class ThreadableJob
|
|
{
|
|
public:
|
|
|
|
enum class ProcessingState : int
|
|
{
|
|
Unstarted,
|
|
Queued,
|
|
InProgress,
|
|
Done
|
|
};
|
|
|
|
ThreadableJob() :
|
|
m_state(ProcessingState::Unstarted)
|
|
{
|
|
}
|
|
|
|
inline ProcessingState state() const
|
|
{
|
|
return m_state.load();
|
|
}
|
|
|
|
inline void reset()
|
|
{
|
|
m_state = ProcessingState::Unstarted;
|
|
}
|
|
|
|
inline void queue()
|
|
{
|
|
m_state = ProcessingState::Queued;
|
|
}
|
|
|
|
inline void done()
|
|
{
|
|
m_state = ProcessingState::Done;
|
|
}
|
|
|
|
void process()
|
|
{
|
|
auto expected = ProcessingState::Queued;
|
|
if (m_state.compare_exchange_strong(expected, ProcessingState::InProgress))
|
|
{
|
|
doProcessing();
|
|
m_state = ProcessingState::Done;
|
|
}
|
|
}
|
|
|
|
virtual bool requiresProcessing() const = 0;
|
|
|
|
|
|
protected:
|
|
virtual void doProcessing() = 0;
|
|
|
|
std::atomic<ProcessingState> m_state;
|
|
} ;
|
|
|
|
#endif
|