mirror of
https://github.com/ZDoom/qzdoom.git
synced 2025-01-18 23:21:41 +00:00
- removed FCriticalSection and replaced all of its uses with std::mutex.
There's really no need for a non-standard solution here anymore with C++11. This also fixes an unreleased lock in the WildMidi code.
This commit is contained in:
parent
3d9dce0156
commit
e091369a38
16 changed files with 45 additions and 402 deletions
|
@ -487,7 +487,6 @@ endif()
|
||||||
# Start defining source files for ZDoom
|
# Start defining source files for ZDoom
|
||||||
set( PLAT_WIN32_SOURCES
|
set( PLAT_WIN32_SOURCES
|
||||||
sound/mididevices/music_win_mididevice.cpp
|
sound/mididevices/music_win_mididevice.cpp
|
||||||
win32/critsec.cpp
|
|
||||||
win32/hardware.cpp
|
win32/hardware.cpp
|
||||||
win32/helperthread.cpp
|
win32/helperthread.cpp
|
||||||
win32/i_cd.cpp
|
win32/i_cd.cpp
|
||||||
|
@ -511,7 +510,6 @@ set( PLAT_POSIX_SOURCES
|
||||||
posix/i_steam.cpp )
|
posix/i_steam.cpp )
|
||||||
set( PLAT_SDL_SOURCES
|
set( PLAT_SDL_SOURCES
|
||||||
posix/sdl/crashcatcher.c
|
posix/sdl/crashcatcher.c
|
||||||
posix/sdl/critsec.cpp
|
|
||||||
posix/sdl/hardware.cpp
|
posix/sdl/hardware.cpp
|
||||||
posix/sdl/i_gui.cpp
|
posix/sdl/i_gui.cpp
|
||||||
posix/sdl/i_input.cpp
|
posix/sdl/i_input.cpp
|
||||||
|
@ -528,7 +526,6 @@ set( PLAT_OSX_SOURCES
|
||||||
posix/osx/i_specialpaths.mm
|
posix/osx/i_specialpaths.mm
|
||||||
posix/osx/zdoom.icns )
|
posix/osx/zdoom.icns )
|
||||||
set( PLAT_COCOA_SOURCES
|
set( PLAT_COCOA_SOURCES
|
||||||
posix/cocoa/critsec.cpp
|
|
||||||
posix/cocoa/i_input.mm
|
posix/cocoa/i_input.mm
|
||||||
posix/cocoa/i_joystick.cpp
|
posix/cocoa/i_joystick.cpp
|
||||||
posix/cocoa/i_main.mm
|
posix/cocoa/i_main.mm
|
||||||
|
|
|
@ -1,37 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
// System independent critical sections without polluting the namespace with the operating system headers.
|
|
||||||
class FInternalCriticalSection;
|
|
||||||
FInternalCriticalSection *CreateCriticalSection();
|
|
||||||
void DeleteCriticalSection(FInternalCriticalSection *c);
|
|
||||||
void EnterCriticalSection(FInternalCriticalSection *c);
|
|
||||||
void LeaveCriticalSection(FInternalCriticalSection *c);
|
|
||||||
|
|
||||||
// This is just a convenience wrapper around the function interface.
|
|
||||||
class FCriticalSection
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
FCriticalSection()
|
|
||||||
{
|
|
||||||
c = CreateCriticalSection();
|
|
||||||
}
|
|
||||||
|
|
||||||
~FCriticalSection()
|
|
||||||
{
|
|
||||||
DeleteCriticalSection(c);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Enter()
|
|
||||||
{
|
|
||||||
EnterCriticalSection(c);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Leave()
|
|
||||||
{
|
|
||||||
LeaveCriticalSection(c);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
FInternalCriticalSection *c;
|
|
||||||
|
|
||||||
};
|
|
|
@ -1,99 +0,0 @@
|
||||||
/*
|
|
||||||
** critsec.cpp
|
|
||||||
**
|
|
||||||
**---------------------------------------------------------------------------
|
|
||||||
** Copyright 2014 Alexey Lysiuk
|
|
||||||
** All rights reserved.
|
|
||||||
**
|
|
||||||
** Redistribution and use in source and binary forms, with or without
|
|
||||||
** modification, are permitted provided that the following conditions
|
|
||||||
** are met:
|
|
||||||
**
|
|
||||||
** 1. Redistributions of source code must retain the above copyright
|
|
||||||
** notice, this list of conditions and the following disclaimer.
|
|
||||||
** 2. Redistributions in binary form must reproduce the above copyright
|
|
||||||
** notice, this list of conditions and the following disclaimer in the
|
|
||||||
** documentation and/or other materials provided with the distribution.
|
|
||||||
** 3. The name of the author may not be used to endorse or promote products
|
|
||||||
** derived from this software without specific prior written permission.
|
|
||||||
**
|
|
||||||
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
||||||
** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
||||||
** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
||||||
** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
||||||
** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
||||||
** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
||||||
** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
**---------------------------------------------------------------------------
|
|
||||||
**
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "critsec.h"
|
|
||||||
|
|
||||||
#include <pthread.h>
|
|
||||||
|
|
||||||
class FInternalCriticalSection
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
FInternalCriticalSection();
|
|
||||||
~FInternalCriticalSection();
|
|
||||||
|
|
||||||
void Enter();
|
|
||||||
void Leave();
|
|
||||||
|
|
||||||
private:
|
|
||||||
pthread_mutex_t m_mutex;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
// TODO: add error handling
|
|
||||||
|
|
||||||
FInternalCriticalSection::FInternalCriticalSection()
|
|
||||||
{
|
|
||||||
pthread_mutexattr_t attributes;
|
|
||||||
pthread_mutexattr_init(&attributes);
|
|
||||||
pthread_mutexattr_settype(&attributes, PTHREAD_MUTEX_RECURSIVE);
|
|
||||||
|
|
||||||
pthread_mutex_init(&m_mutex, &attributes);
|
|
||||||
|
|
||||||
pthread_mutexattr_destroy(&attributes);
|
|
||||||
}
|
|
||||||
|
|
||||||
FInternalCriticalSection::~FInternalCriticalSection()
|
|
||||||
{
|
|
||||||
pthread_mutex_destroy(&m_mutex);
|
|
||||||
}
|
|
||||||
|
|
||||||
void FInternalCriticalSection::Enter()
|
|
||||||
{
|
|
||||||
pthread_mutex_lock(&m_mutex);
|
|
||||||
}
|
|
||||||
|
|
||||||
void FInternalCriticalSection::Leave()
|
|
||||||
{
|
|
||||||
pthread_mutex_unlock(&m_mutex);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
FInternalCriticalSection *CreateCriticalSection()
|
|
||||||
{
|
|
||||||
return new FInternalCriticalSection();
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeleteCriticalSection(FInternalCriticalSection *c)
|
|
||||||
{
|
|
||||||
delete c;
|
|
||||||
}
|
|
||||||
|
|
||||||
void EnterCriticalSection(FInternalCriticalSection *c)
|
|
||||||
{
|
|
||||||
c->Enter();
|
|
||||||
}
|
|
||||||
|
|
||||||
void LeaveCriticalSection(FInternalCriticalSection *c)
|
|
||||||
{
|
|
||||||
c->Leave();
|
|
||||||
}
|
|
|
@ -1,95 +0,0 @@
|
||||||
/*
|
|
||||||
** critsec.cpp
|
|
||||||
**
|
|
||||||
**---------------------------------------------------------------------------
|
|
||||||
** Copyright 2006-2016 Randy Heit
|
|
||||||
** All rights reserved.
|
|
||||||
**
|
|
||||||
** Redistribution and use in source and binary forms, with or without
|
|
||||||
** modification, are permitted provided that the following conditions
|
|
||||||
** are met:
|
|
||||||
**
|
|
||||||
** 1. Redistributions of source code must retain the above copyright
|
|
||||||
** notice, this list of conditions and the following disclaimer.
|
|
||||||
** 2. Redistributions in binary form must reproduce the above copyright
|
|
||||||
** notice, this list of conditions and the following disclaimer in the
|
|
||||||
** documentation and/or other materials provided with the distribution.
|
|
||||||
** 3. The name of the author may not be used to endorse or promote products
|
|
||||||
** derived from this software without specific prior written permission.
|
|
||||||
**
|
|
||||||
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
||||||
** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
||||||
** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
||||||
** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
||||||
** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
||||||
** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
||||||
** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
**---------------------------------------------------------------------------
|
|
||||||
**
|
|
||||||
** Wraps an SDL mutex object. (A critical section is a Windows synchronization
|
|
||||||
** object similar to a mutex but optimized for access by threads belonging to
|
|
||||||
** only one process, hence the class name.)
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "SDL.h"
|
|
||||||
#include "i_system.h"
|
|
||||||
#include "doomerrors.h"
|
|
||||||
|
|
||||||
class FInternalCriticalSection
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
FInternalCriticalSection()
|
|
||||||
{
|
|
||||||
CritSec = SDL_CreateMutex();
|
|
||||||
if (CritSec == NULL)
|
|
||||||
{
|
|
||||||
I_FatalError("Failed to create a critical section mutex.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
~FInternalCriticalSection()
|
|
||||||
{
|
|
||||||
if (CritSec != NULL)
|
|
||||||
{
|
|
||||||
SDL_DestroyMutex(CritSec);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
void Enter()
|
|
||||||
{
|
|
||||||
if (SDL_mutexP(CritSec) != 0)
|
|
||||||
{
|
|
||||||
I_FatalError("Failed entering a critical section.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
void Leave()
|
|
||||||
{
|
|
||||||
if (SDL_mutexV(CritSec) != 0)
|
|
||||||
{
|
|
||||||
I_FatalError("Failed to leave a critical section.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private:
|
|
||||||
SDL_mutex *CritSec;
|
|
||||||
};
|
|
||||||
|
|
||||||
FInternalCriticalSection *CreateCriticalSection()
|
|
||||||
{
|
|
||||||
return new FInternalCriticalSection();
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeleteCriticalSection(FInternalCriticalSection *c)
|
|
||||||
{
|
|
||||||
delete c;
|
|
||||||
}
|
|
||||||
|
|
||||||
void EnterCriticalSection(FInternalCriticalSection *c)
|
|
||||||
{
|
|
||||||
c->Enter();
|
|
||||||
}
|
|
||||||
|
|
||||||
void LeaveCriticalSection(FInternalCriticalSection *c)
|
|
||||||
{
|
|
||||||
c->Leave();
|
|
||||||
}
|
|
|
@ -1,4 +1,5 @@
|
||||||
|
|
||||||
|
#include <mutex>
|
||||||
#include "oplsynth/opl_mus_player.h"
|
#include "oplsynth/opl_mus_player.h"
|
||||||
#include "c_cvars.h"
|
#include "c_cvars.h"
|
||||||
#include "mus2midi.h"
|
#include "mus2midi.h"
|
||||||
|
@ -113,7 +114,7 @@ public:
|
||||||
bool Pause(bool paused);
|
bool Pause(bool paused);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
FCriticalSection CritSec;
|
std::mutex CritSec;
|
||||||
SoundStream *Stream;
|
SoundStream *Stream;
|
||||||
double Tempo;
|
double Tempo;
|
||||||
double Division;
|
double Division;
|
||||||
|
|
|
@ -644,7 +644,7 @@ FString FluidSynthMIDIDevice::GetStats()
|
||||||
}
|
}
|
||||||
FString out;
|
FString out;
|
||||||
|
|
||||||
CritSec.Enter();
|
std::lock_guard<std::mutex> lock(CritSec);
|
||||||
int polyphony = fluid_synth_get_polyphony(FluidSynth);
|
int polyphony = fluid_synth_get_polyphony(FluidSynth);
|
||||||
int voices = fluid_synth_get_active_voice_count(FluidSynth);
|
int voices = fluid_synth_get_active_voice_count(FluidSynth);
|
||||||
double load = fluid_synth_get_cpu_load(FluidSynth);
|
double load = fluid_synth_get_cpu_load(FluidSynth);
|
||||||
|
@ -652,7 +652,6 @@ FString FluidSynthMIDIDevice::GetStats()
|
||||||
fluid_settings_getint(FluidSettings, "synth.chorus.active", &chorus);
|
fluid_settings_getint(FluidSettings, "synth.chorus.active", &chorus);
|
||||||
fluid_settings_getint(FluidSettings, "synth.reverb.active", &reverb);
|
fluid_settings_getint(FluidSettings, "synth.reverb.active", &reverb);
|
||||||
fluid_settings_getint(FluidSettings, "synth.polyphony", &maxpoly);
|
fluid_settings_getint(FluidSettings, "synth.polyphony", &maxpoly);
|
||||||
CritSec.Leave();
|
|
||||||
|
|
||||||
out.Format("Voices: " TEXTCOLOR_YELLOW "%3d" TEXTCOLOR_NORMAL "/" TEXTCOLOR_ORANGE "%3d" TEXTCOLOR_NORMAL "(" TEXTCOLOR_RED "%3d" TEXTCOLOR_NORMAL ")"
|
out.Format("Voices: " TEXTCOLOR_YELLOW "%3d" TEXTCOLOR_NORMAL "/" TEXTCOLOR_ORANGE "%3d" TEXTCOLOR_NORMAL "(" TEXTCOLOR_RED "%3d" TEXTCOLOR_NORMAL ")"
|
||||||
TEXTCOLOR_YELLOW "%6.2f" TEXTCOLOR_NORMAL "%% CPU "
|
TEXTCOLOR_YELLOW "%6.2f" TEXTCOLOR_NORMAL "%% CPU "
|
||||||
|
|
|
@ -237,9 +237,8 @@ void SoftSynthMIDIDevice::Stop()
|
||||||
|
|
||||||
int SoftSynthMIDIDevice::StreamOutSync(MidiHeader *header)
|
int SoftSynthMIDIDevice::StreamOutSync(MidiHeader *header)
|
||||||
{
|
{
|
||||||
CritSec.Enter();
|
std::lock_guard<std::mutex> lock(CritSec);
|
||||||
StreamOut(header);
|
StreamOut(header);
|
||||||
CritSec.Leave();
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -392,7 +391,7 @@ bool SoftSynthMIDIDevice::ServiceStream (void *buff, int numbytes)
|
||||||
samples1 = samples;
|
samples1 = samples;
|
||||||
memset(buff, 0, numbytes);
|
memset(buff, 0, numbytes);
|
||||||
|
|
||||||
CritSec.Enter();
|
std::lock_guard<std::mutex> lock(CritSec);
|
||||||
while (Events != NULL && numsamples > 0)
|
while (Events != NULL && numsamples > 0)
|
||||||
{
|
{
|
||||||
double ticky = NextTickIn;
|
double ticky = NextTickIn;
|
||||||
|
@ -434,7 +433,6 @@ bool SoftSynthMIDIDevice::ServiceStream (void *buff, int numbytes)
|
||||||
{
|
{
|
||||||
res = false;
|
res = false;
|
||||||
}
|
}
|
||||||
CritSec.Leave();
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -167,7 +167,7 @@ FString TimidityMIDIDevice::GetStats()
|
||||||
FString out;
|
FString out;
|
||||||
int i, used;
|
int i, used;
|
||||||
|
|
||||||
CritSec.Enter();
|
std::lock_guard<std::mutex> lock(CritSec);
|
||||||
for (i = used = 0; i < Renderer->voices; ++i)
|
for (i = used = 0; i < Renderer->voices; ++i)
|
||||||
{
|
{
|
||||||
int status = Renderer->voice[i].status;
|
int status = Renderer->voice[i].status;
|
||||||
|
@ -205,7 +205,7 @@ FString TimidityMIDIDevice::GetStats()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
CritSec.Leave();
|
CritSec.unlock();
|
||||||
out.Format(TEXTCOLOR_YELLOW"%3d/%3d ", used, Renderer->voices);
|
out.Format(TEXTCOLOR_YELLOW"%3d/%3d ", used, Renderer->voices);
|
||||||
out += dots;
|
out += dots;
|
||||||
if (Renderer->cut_notes | Renderer->lost_notes)
|
if (Renderer->cut_notes | Renderer->lost_notes)
|
||||||
|
|
|
@ -36,6 +36,7 @@
|
||||||
// HEADER FILES ------------------------------------------------------------
|
// HEADER FILES ------------------------------------------------------------
|
||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
#include <mutex>
|
||||||
#include "i_musicinterns.h"
|
#include "i_musicinterns.h"
|
||||||
|
|
||||||
|
|
||||||
|
@ -73,7 +74,7 @@ protected:
|
||||||
size_t written;
|
size_t written;
|
||||||
DUH *duh;
|
DUH *duh;
|
||||||
DUH_SIGRENDERER *sr;
|
DUH_SIGRENDERER *sr;
|
||||||
FCriticalSection crit_sec;
|
std::mutex crit_sec;
|
||||||
|
|
||||||
bool open2(long pos);
|
bool open2(long pos);
|
||||||
long render(double volume, double delta, long samples, sample_t **buffer);
|
long render(double volume, double delta, long samples, sample_t **buffer);
|
||||||
|
@ -957,18 +958,16 @@ bool input_mod::read(SoundStream *stream, void *buffer, int sizebytes, void *use
|
||||||
memset(buffer, 0, sizebytes);
|
memset(buffer, 0, sizebytes);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
state->crit_sec.Enter();
|
std::lock_guard<std::mutex> lock(state->crit_sec);
|
||||||
while (sizebytes > 0)
|
while (sizebytes > 0)
|
||||||
{
|
{
|
||||||
int written = state->decode_run(buffer, sizebytes / 8);
|
int written = state->decode_run(buffer, sizebytes / 8);
|
||||||
if (written < 0)
|
if (written < 0)
|
||||||
{
|
{
|
||||||
state->crit_sec.Leave();
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (written == 0)
|
if (written == 0)
|
||||||
{
|
{
|
||||||
state->crit_sec.Leave();
|
|
||||||
memset(buffer, 0, sizebytes);
|
memset(buffer, 0, sizebytes);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -983,7 +982,6 @@ bool input_mod::read(SoundStream *stream, void *buffer, int sizebytes, void *use
|
||||||
buffer = (uint8_t *)buffer + written * 8;
|
buffer = (uint8_t *)buffer + written * 8;
|
||||||
sizebytes -= written * 8;
|
sizebytes -= written * 8;
|
||||||
}
|
}
|
||||||
state->crit_sec.Leave();
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1063,18 +1061,16 @@ bool input_mod::SetSubsong(int order)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
crit_sec.Enter();
|
std::lock_guard<std::mutex> lock(crit_sec);
|
||||||
DUH_SIGRENDERER *oldsr = sr;
|
DUH_SIGRENDERER *oldsr = sr;
|
||||||
sr = NULL;
|
sr = NULL;
|
||||||
start_order = order;
|
start_order = order;
|
||||||
if (!open2(0))
|
if (!open2(0))
|
||||||
{
|
{
|
||||||
sr = oldsr;
|
sr = oldsr;
|
||||||
crit_sec.Leave();
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
duh_end_sigrenderer(oldsr);
|
duh_end_sigrenderer(oldsr);
|
||||||
crit_sec.Leave();
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,6 +39,7 @@
|
||||||
|
|
||||||
#include "i_musicinterns.h"
|
#include "i_musicinterns.h"
|
||||||
#include <gme/gme.h>
|
#include <gme/gme.h>
|
||||||
|
#include <mutex>
|
||||||
#include "v_text.h"
|
#include "v_text.h"
|
||||||
#include "templates.h"
|
#include "templates.h"
|
||||||
|
|
||||||
|
@ -56,7 +57,7 @@ public:
|
||||||
FString GetStats();
|
FString GetStats();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
FCriticalSection CritSec;
|
std::mutex CritSec;
|
||||||
Music_Emu *Emu;
|
Music_Emu *Emu;
|
||||||
gme_info_t *TrackInfo;
|
gme_info_t *TrackInfo;
|
||||||
int SampleRate;
|
int SampleRate;
|
||||||
|
@ -251,12 +252,12 @@ bool GMESong::StartTrack(int track, bool getcritsec)
|
||||||
|
|
||||||
if (getcritsec)
|
if (getcritsec)
|
||||||
{
|
{
|
||||||
CritSec.Enter();
|
std::lock_guard<std::mutex> lock(CritSec);
|
||||||
|
err = gme_start_track(Emu, track);
|
||||||
}
|
}
|
||||||
err = gme_start_track(Emu, track);
|
else
|
||||||
if (getcritsec)
|
|
||||||
{
|
{
|
||||||
CritSec.Leave();
|
err = gme_start_track(Emu, track);
|
||||||
}
|
}
|
||||||
if (err != NULL)
|
if (err != NULL)
|
||||||
{
|
{
|
||||||
|
@ -356,7 +357,7 @@ bool GMESong::Read(SoundStream *stream, void *buff, int len, void *userdata)
|
||||||
gme_err_t err;
|
gme_err_t err;
|
||||||
GMESong *song = (GMESong *)userdata;
|
GMESong *song = (GMESong *)userdata;
|
||||||
|
|
||||||
song->CritSec.Enter();
|
std::lock_guard<std::mutex> lock(song->CritSec);
|
||||||
if (gme_track_ended(song->Emu))
|
if (gme_track_ended(song->Emu))
|
||||||
{
|
{
|
||||||
if (song->m_Looping)
|
if (song->m_Looping)
|
||||||
|
@ -366,11 +367,9 @@ bool GMESong::Read(SoundStream *stream, void *buff, int len, void *userdata)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
memset(buff, 0, len);
|
memset(buff, 0, len);
|
||||||
song->CritSec.Leave();
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
err = gme_play(song->Emu, len >> 1, (short *)buff);
|
err = gme_play(song->Emu, len >> 1, (short *)buff);
|
||||||
song->CritSec.Leave();
|
|
||||||
return (err == NULL);
|
return (err == NULL);
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,7 @@
|
||||||
|
|
||||||
// HEADER FILES ------------------------------------------------------------
|
// HEADER FILES ------------------------------------------------------------
|
||||||
|
|
||||||
|
#include <mutex>
|
||||||
#include "i_musicinterns.h"
|
#include "i_musicinterns.h"
|
||||||
#include "v_text.h"
|
#include "v_text.h"
|
||||||
#include "templates.h"
|
#include "templates.h"
|
||||||
|
@ -53,7 +54,7 @@ public:
|
||||||
FString GetStats();
|
FString GetStats();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
FCriticalSection CritSec;
|
std::mutex CritSec;
|
||||||
FileReader Reader;
|
FileReader Reader;
|
||||||
SoundDecoder *Decoder;
|
SoundDecoder *Decoder;
|
||||||
int Channels;
|
int Channels;
|
||||||
|
@ -387,7 +388,7 @@ bool SndFileSong::Read(SoundStream *stream, void *vbuff, int ilen, void *userdat
|
||||||
{
|
{
|
||||||
char *buff = (char*)vbuff;
|
char *buff = (char*)vbuff;
|
||||||
SndFileSong *song = (SndFileSong *)userdata;
|
SndFileSong *song = (SndFileSong *)userdata;
|
||||||
song->CritSec.Enter();
|
std::lock_guard<std::mutex> lock(song->CritSec);
|
||||||
|
|
||||||
size_t len = size_t(ilen);
|
size_t len = size_t(ilen);
|
||||||
size_t currentpos = song->Decoder->getSampleOffset();
|
size_t currentpos = song->Decoder->getSampleOffset();
|
||||||
|
@ -399,7 +400,6 @@ bool SndFileSong::Read(SoundStream *stream, void *vbuff, int ilen, void *userdat
|
||||||
if (currentpos == maxpos)
|
if (currentpos == maxpos)
|
||||||
{
|
{
|
||||||
memset(buff, 0, len);
|
memset(buff, 0, len);
|
||||||
song->CritSec.Leave();
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (currentpos + framestoread > maxpos)
|
if (currentpos + framestoread > maxpos)
|
||||||
|
@ -436,7 +436,6 @@ bool SndFileSong::Read(SoundStream *stream, void *vbuff, int ilen, void *userdat
|
||||||
size_t readlen = song->Decoder->read(buff, len);
|
size_t readlen = song->Decoder->read(buff, len);
|
||||||
if (readlen == 0)
|
if (readlen == 0)
|
||||||
{
|
{
|
||||||
song->CritSec.Leave();
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
buff += readlen;
|
buff += readlen;
|
||||||
|
@ -447,6 +446,5 @@ bool SndFileSong::Read(SoundStream *stream, void *vbuff, int ilen, void *userdat
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
song->CritSec.Leave();
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,10 +67,9 @@ OPLmusicBlock::~OPLmusicBlock()
|
||||||
|
|
||||||
void OPLmusicBlock::ResetChips ()
|
void OPLmusicBlock::ResetChips ()
|
||||||
{
|
{
|
||||||
ChipAccess.Enter();
|
std::lock_guard<std::mutex> lock(ChipAccess);
|
||||||
io->Reset ();
|
io->Reset ();
|
||||||
NumChips = io->Init(MIN(*opl_numchips, 2), FullPan);
|
NumChips = io->Init(MIN(*opl_numchips, 2), FullPan);
|
||||||
ChipAccess.Leave();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void OPLmusicBlock::Restart()
|
void OPLmusicBlock::Restart()
|
||||||
|
@ -255,7 +254,7 @@ bool OPLmusicBlock::ServiceStream (void *buff, int numbytes)
|
||||||
|
|
||||||
memset(buff, 0, numbytes);
|
memset(buff, 0, numbytes);
|
||||||
|
|
||||||
ChipAccess.Enter();
|
std::lock_guard<std::mutex> lock(ChipAccess);
|
||||||
while (numsamples > 0)
|
while (numsamples > 0)
|
||||||
{
|
{
|
||||||
double ticky = NextTickIn;
|
double ticky = NextTickIn;
|
||||||
|
@ -312,7 +311,6 @@ bool OPLmusicBlock::ServiceStream (void *buff, int numbytes)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ChipAccess.Leave();
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#include "critsec.h"
|
#include <mutex>
|
||||||
#include "musicblock.h"
|
#include "musicblock.h"
|
||||||
|
|
||||||
class FileReader;
|
class FileReader;
|
||||||
|
@ -28,7 +28,7 @@ protected:
|
||||||
double LastOffset;
|
double LastOffset;
|
||||||
bool FullPan;
|
bool FullPan;
|
||||||
|
|
||||||
FCriticalSection ChipAccess;
|
std::mutex ChipAccess;
|
||||||
};
|
};
|
||||||
|
|
||||||
class OPLmusicFile : public OPLmusicBlock
|
class OPLmusicFile : public OPLmusicBlock
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
#include <mutex>
|
||||||
#include "timidity.h"
|
#include "timidity.h"
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "instrum.h"
|
#include "instrum.h"
|
||||||
|
@ -37,13 +38,12 @@
|
||||||
#include "c_cvars.h"
|
#include "c_cvars.h"
|
||||||
#include "tables.h"
|
#include "tables.h"
|
||||||
#include "effect.h"
|
#include "effect.h"
|
||||||
#include "critsec.h"
|
|
||||||
#include "i_musicinterns.h"
|
#include "i_musicinterns.h"
|
||||||
|
|
||||||
|
|
||||||
namespace TimidityPlus
|
namespace TimidityPlus
|
||||||
{
|
{
|
||||||
FCriticalSection CvarCritSec;
|
std::mutex CvarCritSec;
|
||||||
bool timidity_modulation_wheel = true;
|
bool timidity_modulation_wheel = true;
|
||||||
bool timidity_portamento = false;
|
bool timidity_portamento = false;
|
||||||
int timidity_reverb = 0;
|
int timidity_reverb = 0;
|
||||||
|
@ -73,9 +73,8 @@ namespace TimidityPlus
|
||||||
|
|
||||||
template<class T> void ChangeVarSync(T&var, T value)
|
template<class T> void ChangeVarSync(T&var, T value)
|
||||||
{
|
{
|
||||||
TimidityPlus::CvarCritSec.Enter();
|
std::lock_guard<std::mutex> lock(TimidityPlus::CvarCritSec);
|
||||||
var = value;
|
var = value;
|
||||||
TimidityPlus::CvarCritSec.Leave();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CUSTOM_CVAR(Bool, timidity_modulation_wheel, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
|
CUSTOM_CVAR(Bool, timidity_modulation_wheel, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
|
||||||
|
@ -5128,7 +5127,7 @@ int Player::compute_data(float *buffer, int32_t count)
|
||||||
{
|
{
|
||||||
if (count == 0) return RC_OK;
|
if (count == 0) return RC_OK;
|
||||||
|
|
||||||
CvarCritSec.Enter();
|
std::lock_guard<std::mutex> lock(CvarCritSec);
|
||||||
|
|
||||||
if (last_reverb_setting != timidity_reverb)
|
if (last_reverb_setting != timidity_reverb)
|
||||||
{
|
{
|
||||||
|
@ -5154,7 +5153,6 @@ int Player::compute_data(float *buffer, int32_t count)
|
||||||
*buffer++ = (common_buffer[i])*(5.f / 0x80000000u);
|
*buffer++ = (common_buffer[i])*(5.f / 0x80000000u);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
CvarCritSec.Leave();
|
|
||||||
return RC_OK;
|
return RC_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,6 +36,7 @@
|
||||||
#endif
|
#endif
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "wm_error.h"
|
#include "wm_error.h"
|
||||||
|
@ -43,7 +44,6 @@
|
||||||
#include "reverb.h"
|
#include "reverb.h"
|
||||||
#include "gus_pat.h"
|
#include "gus_pat.h"
|
||||||
#include "wildmidi_lib.h"
|
#include "wildmidi_lib.h"
|
||||||
#include "critsec.h"
|
|
||||||
#include "files.h"
|
#include "files.h"
|
||||||
#include "i_soundfont.h"
|
#include "i_soundfont.h"
|
||||||
|
|
||||||
|
@ -84,7 +84,7 @@ static int fix_release = 0;
|
||||||
static int auto_amp = 0;
|
static int auto_amp = 0;
|
||||||
static int auto_amp_with_amp = 0;
|
static int auto_amp_with_amp = 0;
|
||||||
|
|
||||||
static FCriticalSection patch_lock;
|
static std::mutex patch_lock;
|
||||||
extern std::unique_ptr<FSoundFontReader> wm_sfreader;
|
extern std::unique_ptr<FSoundFontReader> wm_sfreader;
|
||||||
|
|
||||||
struct _channel {
|
struct _channel {
|
||||||
|
@ -151,7 +151,7 @@ struct _mdi {
|
||||||
reverb = NULL;
|
reverb = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
FCriticalSection lock;
|
std::mutex lock;
|
||||||
unsigned long int samples_to_mix;
|
unsigned long int samples_to_mix;
|
||||||
|
|
||||||
unsigned short midi_master_vol;
|
unsigned short midi_master_vol;
|
||||||
|
@ -179,7 +179,7 @@ static double newt_coeffs[58][58]; /* for start/end of samples */
|
||||||
#define MAX_GAUSS_ORDER 34 /* 34 is as high as we can go before errors crop up */
|
#define MAX_GAUSS_ORDER 34 /* 34 is as high as we can go before errors crop up */
|
||||||
static double *gauss_table = NULL; /* *gauss_table[1<<FPBITS] */
|
static double *gauss_table = NULL; /* *gauss_table[1<<FPBITS] */
|
||||||
static int gauss_n = MAX_GAUSS_ORDER;
|
static int gauss_n = MAX_GAUSS_ORDER;
|
||||||
static FCriticalSection gauss_lock;
|
static std::mutex gauss_lock;
|
||||||
|
|
||||||
static void init_gauss(void) {
|
static void init_gauss(void) {
|
||||||
/* init gauss table */
|
/* init gauss table */
|
||||||
|
@ -192,9 +192,8 @@ static void init_gauss(void) {
|
||||||
double z[35];
|
double z[35];
|
||||||
double *gptr, *t;
|
double *gptr, *t;
|
||||||
|
|
||||||
gauss_lock.Enter();
|
std::lock_guard<std::mutex> lock(gauss_lock);
|
||||||
if (gauss_table) {
|
if (gauss_table) {
|
||||||
gauss_lock.Leave();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -241,14 +240,13 @@ static void init_gauss(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
gauss_table = t;
|
gauss_table = t;
|
||||||
gauss_lock.Leave();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void free_gauss(void) {
|
static void free_gauss(void)
|
||||||
gauss_lock.Enter();
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(gauss_lock);
|
||||||
free(gauss_table);
|
free(gauss_table);
|
||||||
gauss_table = NULL;
|
gauss_table = NULL;
|
||||||
gauss_lock.Leave();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct _hndl {
|
struct _hndl {
|
||||||
|
@ -562,7 +560,7 @@ static void WM_FreePatches(void) {
|
||||||
struct _patch * tmp_patch;
|
struct _patch * tmp_patch;
|
||||||
struct _sample * tmp_sample;
|
struct _sample * tmp_sample;
|
||||||
|
|
||||||
patch_lock.Enter();
|
std::lock_guard<std::mutex> lock(patch_lock);
|
||||||
for (i = 0; i < 128; i++) {
|
for (i = 0; i < 128; i++) {
|
||||||
while (patch[i]) {
|
while (patch[i]) {
|
||||||
while (patch[i]->first_sample) {
|
while (patch[i]->first_sample) {
|
||||||
|
@ -577,7 +575,6 @@ static void WM_FreePatches(void) {
|
||||||
patch[i] = tmp_patch;
|
patch[i] = tmp_patch;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
patch_lock.Leave();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* wm_strdup -- adds extra space for appending up to 4 chars */
|
/* wm_strdup -- adds extra space for appending up to 4 chars */
|
||||||
|
@ -1324,27 +1321,23 @@ static struct _patch *
|
||||||
get_patch_data(unsigned short patchid) {
|
get_patch_data(unsigned short patchid) {
|
||||||
struct _patch *search_patch;
|
struct _patch *search_patch;
|
||||||
|
|
||||||
patch_lock.Enter();
|
std::lock_guard<std::mutex> lock(patch_lock);
|
||||||
|
|
||||||
search_patch = patch[patchid & 0x007F];
|
search_patch = patch[patchid & 0x007F];
|
||||||
|
|
||||||
if (search_patch == NULL) {
|
if (search_patch == NULL) {
|
||||||
patch_lock.Leave();
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (search_patch) {
|
while (search_patch) {
|
||||||
if (search_patch->patchid == patchid) {
|
if (search_patch->patchid == patchid) {
|
||||||
patch_lock.Leave();
|
|
||||||
return search_patch;
|
return search_patch;
|
||||||
}
|
}
|
||||||
search_patch = search_patch->next;
|
search_patch = search_patch->next;
|
||||||
}
|
}
|
||||||
if ((patchid >> 8) != 0) {
|
if ((patchid >> 8) != 0) {
|
||||||
patch_lock.Leave();
|
|
||||||
return (get_patch_data(patchid & 0x00FF));
|
return (get_patch_data(patchid & 0x00FF));
|
||||||
}
|
}
|
||||||
patch_lock.Leave();
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1363,16 +1356,14 @@ static void load_patch(struct _mdi *mdi, unsigned short patchid) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
patch_lock.Enter();
|
std::lock_guard<std::mutex> lock(patch_lock);
|
||||||
if (!tmp_patch->loaded) {
|
if (!tmp_patch->loaded) {
|
||||||
if (load_sample(tmp_patch) == -1) {
|
if (load_sample(tmp_patch) == -1) {
|
||||||
patch_lock.Leave();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tmp_patch->first_sample == NULL) {
|
if (tmp_patch->first_sample == NULL) {
|
||||||
patch_lock.Leave();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1381,7 +1372,6 @@ static void load_patch(struct _mdi *mdi, unsigned short patchid) {
|
||||||
(sizeof(struct _patch*) * mdi->patch_count));
|
(sizeof(struct _patch*) * mdi->patch_count));
|
||||||
mdi->patches[mdi->patch_count - 1] = tmp_patch;
|
mdi->patches[mdi->patch_count - 1] = tmp_patch;
|
||||||
tmp_patch->inuse_count++;
|
tmp_patch->inuse_count++;
|
||||||
patch_lock.Leave();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct _sample *
|
static struct _sample *
|
||||||
|
@ -1389,17 +1379,14 @@ get_sample_data(struct _patch *sample_patch, unsigned long int freq) {
|
||||||
struct _sample *last_sample = NULL;
|
struct _sample *last_sample = NULL;
|
||||||
struct _sample *return_sample = NULL;
|
struct _sample *return_sample = NULL;
|
||||||
|
|
||||||
patch_lock.Enter();
|
std::lock_guard<std::mutex> lock(patch_lock);
|
||||||
if (sample_patch == NULL) {
|
if (sample_patch == NULL) {
|
||||||
patch_lock.Leave();
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (sample_patch->first_sample == NULL) {
|
if (sample_patch->first_sample == NULL) {
|
||||||
patch_lock.Leave();
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (freq == 0) {
|
if (freq == 0) {
|
||||||
patch_lock.Leave();
|
|
||||||
return sample_patch->first_sample;
|
return sample_patch->first_sample;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1408,7 +1395,6 @@ get_sample_data(struct _patch *sample_patch, unsigned long int freq) {
|
||||||
while (last_sample) {
|
while (last_sample) {
|
||||||
if (freq > last_sample->freq_low) {
|
if (freq > last_sample->freq_low) {
|
||||||
if (freq < last_sample->freq_high) {
|
if (freq < last_sample->freq_high) {
|
||||||
patch_lock.Leave();
|
|
||||||
return last_sample;
|
return last_sample;
|
||||||
} else {
|
} else {
|
||||||
return_sample = last_sample;
|
return_sample = last_sample;
|
||||||
|
@ -1416,7 +1402,6 @@ get_sample_data(struct _patch *sample_patch, unsigned long int freq) {
|
||||||
}
|
}
|
||||||
last_sample = last_sample->next;
|
last_sample = last_sample->next;
|
||||||
}
|
}
|
||||||
patch_lock.Leave();
|
|
||||||
return return_sample;
|
return return_sample;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2100,7 +2085,7 @@ static void freeMDI(struct _mdi *mdi) {
|
||||||
unsigned long int i;
|
unsigned long int i;
|
||||||
|
|
||||||
if (mdi->patch_count != 0) {
|
if (mdi->patch_count != 0) {
|
||||||
patch_lock.Enter();
|
std::lock_guard<std::mutex> lock(patch_lock);
|
||||||
for (i = 0; i < mdi->patch_count; i++) {
|
for (i = 0; i < mdi->patch_count; i++) {
|
||||||
mdi->patches[i]->inuse_count--;
|
mdi->patches[i]->inuse_count--;
|
||||||
if (mdi->patches[i]->inuse_count == 0) {
|
if (mdi->patches[i]->inuse_count == 0) {
|
||||||
|
@ -2114,7 +2099,6 @@ static void freeMDI(struct _mdi *mdi) {
|
||||||
mdi->patches[i]->loaded = 0;
|
mdi->patches[i]->loaded = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
patch_lock.Leave();
|
|
||||||
free(mdi->patches);
|
free(mdi->patches);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2632,7 +2616,7 @@ WM_SYMBOL int WildMidi_Close(midi * handle) {
|
||||||
0);
|
0);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
mdi->lock.Enter();
|
std::lock_guard<std::mutex> lock(mdi->lock);
|
||||||
if (first_handle->handle == handle) {
|
if (first_handle->handle == handle) {
|
||||||
tmp_handle = first_handle->next;
|
tmp_handle = first_handle->next;
|
||||||
free(first_handle);
|
free(first_handle);
|
||||||
|
@ -2703,17 +2687,15 @@ WM_SYMBOL int WildMidi_SetOption(midi * handle, unsigned short int options,
|
||||||
}
|
}
|
||||||
|
|
||||||
mdi = (struct _mdi *) handle;
|
mdi = (struct _mdi *) handle;
|
||||||
mdi->lock.Enter();
|
std::lock_guard<std::mutex> lock(mdi->lock);
|
||||||
if ((!(options & 0x0007)) || (options & 0xFFF8)) {
|
if ((!(options & 0x0007)) || (options & 0xFFF8)) {
|
||||||
_WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_INVALID_ARG, "(invalid option)",
|
_WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_INVALID_ARG, "(invalid option)",
|
||||||
0);
|
0);
|
||||||
mdi->lock.Leave();
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (setting & 0xFFF8) {
|
if (setting & 0xFFF8) {
|
||||||
_WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_INVALID_ARG,
|
_WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_INVALID_ARG,
|
||||||
"(invalid setting)", 0);
|
"(invalid setting)", 0);
|
||||||
mdi->lock.Leave();
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2727,7 +2709,6 @@ WM_SYMBOL int WildMidi_SetOption(midi * handle, unsigned short int options,
|
||||||
_WM_reset_reverb(mdi->reverb);
|
_WM_reset_reverb(mdi->reverb);
|
||||||
}
|
}
|
||||||
|
|
||||||
mdi->lock.Leave();
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2743,12 +2724,11 @@ WildMidi_GetInfo(midi * handle) {
|
||||||
0);
|
0);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
mdi->lock.Enter();
|
std::lock_guard<std::mutex> lock(mdi->lock);
|
||||||
if (mdi->tmp_info == NULL) {
|
if (mdi->tmp_info == NULL) {
|
||||||
mdi->tmp_info = (struct _WM_Info*)malloc(sizeof(struct _WM_Info));
|
mdi->tmp_info = (struct _WM_Info*)malloc(sizeof(struct _WM_Info));
|
||||||
if (mdi->tmp_info == NULL) {
|
if (mdi->tmp_info == NULL) {
|
||||||
_WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_MEM, "to set info", 0);
|
_WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_MEM, "to set info", 0);
|
||||||
mdi->lock.Leave();
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
mdi->tmp_info->copyright = NULL;
|
mdi->tmp_info->copyright = NULL;
|
||||||
|
@ -2763,7 +2743,6 @@ WildMidi_GetInfo(midi * handle) {
|
||||||
} else {
|
} else {
|
||||||
mdi->tmp_info->copyright = NULL;
|
mdi->tmp_info->copyright = NULL;
|
||||||
}
|
}
|
||||||
mdi->lock.Leave();
|
|
||||||
return mdi->tmp_info;
|
return mdi->tmp_info;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,89 +0,0 @@
|
||||||
/*
|
|
||||||
**
|
|
||||||
**
|
|
||||||
**---------------------------------------------------------------------------
|
|
||||||
** Copyright 2005-2016 Randy Heit
|
|
||||||
** All rights reserved.
|
|
||||||
**
|
|
||||||
** Redistribution and use in source and binary forms, with or without
|
|
||||||
** modification, are permitted provided that the following conditions
|
|
||||||
** are met:
|
|
||||||
**
|
|
||||||
** 1. Redistributions of source code must retain the above copyright
|
|
||||||
** notice, this list of conditions and the following disclaimer.
|
|
||||||
** 2. Redistributions in binary form must reproduce the above copyright
|
|
||||||
** notice, this list of conditions and the following disclaimer in the
|
|
||||||
** documentation and/or other materials provided with the distribution.
|
|
||||||
** 3. The name of the author may not be used to endorse or promote products
|
|
||||||
** derived from this software without specific prior written permission.
|
|
||||||
**
|
|
||||||
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
||||||
** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
||||||
** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
||||||
** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
||||||
** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
||||||
** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
||||||
** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
**---------------------------------------------------------------------------
|
|
||||||
**
|
|
||||||
*/
|
|
||||||
// Wraps a Windows critical section object.
|
|
||||||
|
|
||||||
#ifndef _WINNT_
|
|
||||||
#define WIN32_LEAN_AND_MEAN
|
|
||||||
#include <windows.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
class FInternalCriticalSection
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
FInternalCriticalSection()
|
|
||||||
{
|
|
||||||
InitializeCriticalSection(&CritSec);
|
|
||||||
}
|
|
||||||
~FInternalCriticalSection()
|
|
||||||
{
|
|
||||||
DeleteCriticalSection(&CritSec);
|
|
||||||
}
|
|
||||||
void Enter()
|
|
||||||
{
|
|
||||||
EnterCriticalSection(&CritSec);
|
|
||||||
}
|
|
||||||
void Leave()
|
|
||||||
{
|
|
||||||
LeaveCriticalSection(&CritSec);
|
|
||||||
}
|
|
||||||
#if 0
|
|
||||||
// SDL has no equivalent functionality, so better not use it on Windows.
|
|
||||||
bool TryEnter()
|
|
||||||
{
|
|
||||||
return TryEnterCriticalSection(&CritSec) != 0;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
private:
|
|
||||||
CRITICAL_SECTION CritSec;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
FInternalCriticalSection *CreateCriticalSection()
|
|
||||||
{
|
|
||||||
return new FInternalCriticalSection();
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeleteCriticalSection(FInternalCriticalSection *c)
|
|
||||||
{
|
|
||||||
delete c;
|
|
||||||
}
|
|
||||||
|
|
||||||
void EnterCriticalSection(FInternalCriticalSection *c)
|
|
||||||
{
|
|
||||||
c->Enter();
|
|
||||||
}
|
|
||||||
|
|
||||||
void LeaveCriticalSection(FInternalCriticalSection *c)
|
|
||||||
{
|
|
||||||
c->Leave();
|
|
||||||
}
|
|
Loading…
Reference in a new issue