drop usage of std::deque, part 2

This commit is contained in:
tildearrow 2023-09-13 02:46:02 -05:00
parent 8b565ed284
commit 9a63fdccd5
36 changed files with 38 additions and 38 deletions

View file

@ -37,7 +37,7 @@
#include <mutex>
#include <map>
#include <unordered_map>
#include "fixedQueue.h"
#include "../fixedQueue.h"
class DivWorkPool;

View file

@ -1,180 +0,0 @@
/**
* Furnace Tracker - multi-system chiptune tracker
* Copyright (C) 2021-2023 tildearrow and contributors
*
* 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; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef _FIXED_QUEUE_H
#define _FIXED_QUEUE_H
#include <stdint.h>
#include "../ta-log.h"
template<typename T, size_t items> struct FixedQueue {
size_t readPos, writePos;
T data[items];
T& operator[](size_t pos);
T& front();
T& back();
bool pop();
bool push(const T& item);
bool erase(size_t pos);
bool pop_front();
bool pop_back();
bool push_front(const T& item);
bool push_back(const T& item);
void clear();
bool empty();
size_t size();
FixedQueue():
readPos(0),
writePos(0) {}
};
template <typename T, size_t items> T& FixedQueue<T,items>::operator[](size_t pos) {
if (pos>=size()) {
logW("accessing invalid position. bug!");
}
return data[(readPos+pos)%items];
}
template <typename T, size_t items> T& FixedQueue<T,items>::front() {
return data[readPos];
}
template <typename T, size_t items> T& FixedQueue<T,items>::back() {
if (writePos==0) return data[items-1];
return data[writePos-1];
}
template <typename T, size_t items> bool FixedQueue<T,items>::erase(size_t pos) {
size_t curSize=size();
if (pos>=curSize) {
logW("accessing invalid position. bug!");
return false;
}
if (pos==0) {
return pop_front();
}
if (pos==curSize-1) {
return pop_back();
}
for (size_t i=0, p=(readPos+pos)%items, p1=(readPos+pos+1)%items; i<=curSize; i++) {
if (p>=items) p-=items;
if (p1>=items) p1-=items;
data[p]=data[p1];
p++;
p1++;
}
if (writePos>0) {
writePos--;
} else {
writePos=items-1;
}
return true;
}
template <typename T, size_t items> bool FixedQueue<T,items>::pop() {
if (readPos==writePos) return false;
if (++readPos>=items) readPos=0;
return true;
}
template <typename T, size_t items> bool FixedQueue<T,items>::push(const T& item) {
if (writePos==(readPos-1)) {
logW("queue overflow!");
return false;
}
if (writePos==items-1 && readPos==0) {
logW("queue overflow!");
return false;
}
data[writePos]=item;
if (++writePos>=items) writePos=0;
return true;
}
template <typename T, size_t items> bool FixedQueue<T,items>::pop_front() {
if (readPos==writePos) return false;
if (++readPos>=items) readPos=0;
return true;
}
template <typename T, size_t items> bool FixedQueue<T,items>::push_back(const T& item) {
if (writePos==(readPos-1)) {
logW("queue overflow!");
return false;
}
if (writePos==items-1 && readPos==0) {
logW("queue overflow!");
return false;
}
data[writePos]=item;
if (++writePos>=items) writePos=0;
return true;
}
template <typename T, size_t items> bool FixedQueue<T,items>::pop_back() {
if (readPos==writePos) return false;
if (writePos>0) {
writePos--;
} else {
writePos=items-1;
}
return true;
}
template <typename T, size_t items> bool FixedQueue<T,items>::push_front(const T& item) {
if (readPos==(writePos+1)) {
logW("stack overflow!");
return false;
}
if (readPos==0 && writePos==items-1) {
logW("stack overflow!");
return false;
}
if (readPos>0) {
readPos--;
} else {
readPos=items-1;
}
data[readPos]=item;
return true;
}
template <typename T, size_t items> void FixedQueue<T,items>::clear() {
readPos=0;
writePos=0;
}
template <typename T, size_t items> bool FixedQueue<T,items>::empty() {
return (readPos==writePos);
}
template <typename T, size_t items> size_t FixedQueue<T,items>::size() {
if (readPos>writePos) {
return items+writePos-readPos;
}
return writePos-readPos;
}
#endif

View file

@ -20,7 +20,7 @@
#ifndef _AY_H
#define _AY_H
#include "../dispatch.h"
#include "../fixedQueue.h"
#include "../../fixedQueue.h"
#include "sound/ay8910.h"
class DivPlatformAY8910: public DivDispatch {

View file

@ -20,7 +20,7 @@
#ifndef _AY8930_H
#define _AY8930_H
#include "../dispatch.h"
#include "../fixedQueue.h"
#include "../../fixedQueue.h"
#include "sound/ay8910.h"
class DivPlatformAY8930: public DivDispatch {

View file

@ -22,7 +22,7 @@
#include "../dispatch.h"
#include "sound/c140_c219.h"
#include "../fixedQueue.h"
#include "../../fixedQueue.h"
class DivPlatformC140: public DivDispatch {
struct Channel: public SharedChannel<int> {

View file

@ -21,7 +21,7 @@
#define _C64_H
#include "../dispatch.h"
#include "../fixedQueue.h"
#include "../../fixedQueue.h"
#include "sound/c64/sid.h"
#include "sound/c64_fp/SID.h"
#include "sound/c64_d/dsid.h"

View file

@ -22,7 +22,7 @@
#include "../dispatch.h"
#include "../engine.h"
#include "../fixedQueue.h"
#include "../../fixedQueue.h"
#include "../macroInt.h"
#include "../sample.h"
#include "vgsound_emu/src/es550x/es5506.hpp"

View file

@ -22,7 +22,7 @@
#include "../dispatch.h"
#include "../instrument.h"
#include "../fixedQueue.h"
#include "../../fixedQueue.h"
#define KVS(x,y) ((chan[x].state.op[y].kvs==2 && isOutput[chan[x].state.alg][y]) || chan[x].state.op[y].kvs==1)

View file

@ -21,7 +21,7 @@
#define _GA20_H
#include "../dispatch.h"
#include "../fixedQueue.h"
#include "../../fixedQueue.h"
#include "../macroInt.h"
#include "sound/ga20/iremga20.h"

View file

@ -23,7 +23,7 @@
#include "../dispatch.h"
#include "../waveSynth.h"
#include "sound/gb/gb.h"
#include "../fixedQueue.h"
#include "../../fixedQueue.h"
class DivPlatformGB: public DivDispatch {
struct Channel: public SharedChannel<signed char> {

View file

@ -21,7 +21,7 @@
#define _K007232_H
#include "../dispatch.h"
#include "../fixedQueue.h"
#include "../../fixedQueue.h"
#include "../macroInt.h"
#include "vgsound_emu/src/k007232/k007232.hpp"

View file

@ -21,7 +21,7 @@
#define _MSM5232_H
#include "../dispatch.h"
#include "../fixedQueue.h"
#include "../../fixedQueue.h"
#include "sound/oki/msm5232.h"
class DivPlatformMSM5232: public DivDispatch {

View file

@ -21,7 +21,7 @@
#define _MSM6258_H
#include "../dispatch.h"
#include "../fixedQueue.h"
#include "../../fixedQueue.h"
#include "sound/oki/okim6258.h"
class DivPlatformMSM6258: public DivDispatch {

View file

@ -21,7 +21,7 @@
#define _MSM6295_H
#include "../dispatch.h"
#include "../fixedQueue.h"
#include "../../fixedQueue.h"
#include "vgsound_emu/src/msm6295/msm6295.hpp"
class DivPlatformMSM6295: public DivDispatch, public vgsound_emu_mem_intf {

View file

@ -21,7 +21,7 @@
#define _N163_H
#include "../dispatch.h"
#include "../fixedQueue.h"
#include "../../fixedQueue.h"
#include "../waveSynth.h"
#include "vgsound_emu/src/n163/n163.hpp"

View file

@ -21,7 +21,7 @@
#define _NAMCOWSG_H
#include "../dispatch.h"
#include "../fixedQueue.h"
#include "../../fixedQueue.h"
#include "../waveSynth.h"
#include "sound/namco.h"

View file

@ -21,7 +21,7 @@
#define _OPL_H
#include "../dispatch.h"
#include "../fixedQueue.h"
#include "../../fixedQueue.h"
#include "../../../extern/opl/opl3.h"
#include "sound/ymfm/ymfm_adpcm.h"

View file

@ -21,7 +21,7 @@
#define _OPLL_H
#include "../dispatch.h"
#include "../fixedQueue.h"
#include "../../fixedQueue.h"
extern "C" {
#include "../../../extern/Nuked-OPLL/opll.h"

View file

@ -21,7 +21,7 @@
#define _PCE_H
#include "../dispatch.h"
#include "../fixedQueue.h"
#include "../../fixedQueue.h"
#include "../waveSynth.h"
#include "sound/pce_psg.h"

View file

@ -21,7 +21,7 @@
#define _PCSPKR_H
#include "../dispatch.h"
#include "../fixedQueue.h"
#include "../../fixedQueue.h"
#include <thread>
#include <mutex>
#include <condition_variable>

View file

@ -21,7 +21,7 @@
#define _POKEY_H
#include "../dispatch.h"
#include "../fixedQueue.h"
#include "../../fixedQueue.h"
extern "C" {
#include "sound/pokey/mzpokeysnd.h"

View file

@ -21,7 +21,7 @@
#define _SAA_H
#include "../dispatch.h"
#include "../fixedQueue.h"
#include "../../fixedQueue.h"
#include "../../../extern/SAASound/src/SAASound.h"
class DivPlatformSAA1099: public DivDispatch {

View file

@ -23,7 +23,7 @@
#include "../dispatch.h"
#include "../instrument.h"
#include "sound/segapcm.h"
#include "../fixedQueue.h"
#include "../../fixedQueue.h"
class DivPlatformSegaPCM: public DivDispatch {
protected:

View file

@ -21,7 +21,7 @@
#define _SM8521_H
#include "../dispatch.h"
#include "../fixedQueue.h"
#include "../../fixedQueue.h"
#include "../waveSynth.h"
#include "sound/sm8521.h"

View file

@ -25,7 +25,7 @@
extern "C" {
#include "../../../extern/Nuked-PSG/ympsg.h"
}
#include "../fixedQueue.h"
#include "../../fixedQueue.h"
class DivPlatformSMS: public DivDispatch {
struct Channel: public SharedChannel<signed char> {

View file

@ -22,7 +22,7 @@
#include "../dispatch.h"
#include "../waveSynth.h"
#include "../fixedQueue.h"
#include "../../fixedQueue.h"
#include "sound/snes/SPC_DSP.h"
class DivPlatformSNES: public DivDispatch {

View file

@ -21,7 +21,7 @@
#define _SU_H
#include "../dispatch.h"
#include "../fixedQueue.h"
#include "../../fixedQueue.h"
#include "sound/su.h"
class DivPlatformSoundUnit: public DivDispatch {

View file

@ -23,7 +23,7 @@
#include "../dispatch.h"
#include "../waveSynth.h"
#include "sound/swan.h"
#include "../fixedQueue.h"
#include "../../fixedQueue.h"
class DivPlatformSwan: public DivDispatch {
struct Channel: public SharedChannel<int> {

View file

@ -21,7 +21,7 @@
#define _T6W28_H
#include "../dispatch.h"
#include "../fixedQueue.h"
#include "../../fixedQueue.h"
#include "sound/t6w28/T6W28_Apu.h"
class DivPlatformT6W28: public DivDispatch {

View file

@ -21,7 +21,7 @@
#define _TED_H
#include "../dispatch.h"
#include "../fixedQueue.h"
#include "../../fixedQueue.h"
#include "sound/ted-sound.h"
class DivPlatformTED: public DivDispatch {

View file

@ -21,7 +21,7 @@
#define _TX81Z_H
#include "fmshared_OPM.h"
#include "../fixedQueue.h"
#include "../../fixedQueue.h"
#include "sound/ymfm/ymfm_opz.h"
class DivTXInterface: public ymfm::ymfm_interface {

View file

@ -21,7 +21,7 @@
#define _PLATFORM_VB_H
#include "../dispatch.h"
#include "../fixedQueue.h"
#include "../../fixedQueue.h"
#include "../waveSynth.h"
#include "sound/vsu.h"

View file

@ -20,7 +20,7 @@
#ifndef _VRC6_H
#define _VRC6_H
#include "../fixedQueue.h"
#include "../../fixedQueue.h"
#include "../dispatch.h"
#include "vgsound_emu/src/vrcvi/vrcvi.hpp"

View file

@ -24,7 +24,7 @@
#include "defines.h"
#include "safeWriter.h"
#include "dataErrors.h"
#include "fixedQueue.h"
#include "../fixedQueue.h"
enum DivSampleLoopMode: unsigned char {
DIV_SAMPLE_LOOP_FORWARD=0,

View file

@ -26,7 +26,7 @@
#include <functional>
#include <future>
#include "fixedQueue.h"
#include "../fixedQueue.h"
class DivWorkPool;