Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove CriticalSection, replace with std::mutex #2765

Merged
merged 1 commit into from
Oct 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,6 @@ set(SURGE_COMMON_SOURCES
src/common/dsp/Wavetable.cpp
src/common/dsp/WavetableOscillator.cpp
src/common/dsp/WindowOscillator.cpp
src/common/thread/CriticalSection.cpp
src/common/util/FpuState.cpp
src/common/vt_dsp/basic_dsp.cpp
src/common/vt_dsp/halfratefilter.cpp
Expand Down
4 changes: 2 additions & 2 deletions src/common/SurgePatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -975,7 +975,7 @@ void SurgePatch::load_patch(const void* data, int datasize, bool preset)

void* d = (void*)((char*)dr + sizeof(wt_header));

storage->CS_WaveTableData.enter();
storage->waveTableDataMutex.lock();
scene[sc].osc[osc].wt.BuildWT(d, *wth, false);
if( scene[sc].osc[osc].wavetable_display_name[0] == '\0' )
{
Expand All @@ -988,7 +988,7 @@ void SurgePatch::load_patch(const void* data, int datasize, bool preset)
strncpy(scene[sc].osc[osc].wavetable_display_name, "(Patch Wavetable)", 256);
}
}
storage->CS_WaveTableData.leave();
storage->waveTableDataMutex.unlock();

dr += ph->wtsize[sc][osc];
}
Expand Down
19 changes: 8 additions & 11 deletions src/common/SurgeStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -978,10 +978,10 @@ bool SurgeStorage::load_wt_wt(string filename, Wavetable* wt)
data = malloc(ds);
read = fread(data, 1, ds, f);
// FIXME - error if read != ds
CS_WaveTableData.enter();

waveTableDataMutex.lock();
bool wasBuilt = wt->BuildWT(data, wh, false);
CS_WaveTableData.leave();
waveTableDataMutex.unlock();
free(data);

if (!wasBuilt)
Expand Down Expand Up @@ -1086,8 +1086,7 @@ void SurgeStorage::clipboard_copy(int type, int scene, int entry)
return;
}

// CS ENTER
CS_ModRouting.enter();
modRoutingMutex.lock();
{

clipboard_p.clear();
Expand Down Expand Up @@ -1138,8 +1137,7 @@ void SurgeStorage::clipboard_copy(int type, int scene, int entry)
}
}
}
// CS LEAVE
CS_ModRouting.leave();
modRoutingMutex.unlock();
}

void SurgeStorage::clipboard_paste(int type, int scene, int entry)
Expand Down Expand Up @@ -1191,8 +1189,7 @@ void SurgeStorage::clipboard_paste(int type, int scene, int entry)
return;
}

// CS ENTER
CS_ModRouting.enter();
modRoutingMutex.lock();
{

for (int i = start; i < n; i++)
Expand Down Expand Up @@ -1274,8 +1271,8 @@ void SurgeStorage::clipboard_paste(int type, int scene, int entry)
}
}
}
// CS LEAVE
CS_ModRouting.leave();

modRoutingMutex.unlock();
}

TiXmlElement* SurgeStorage::getSnapshotSection(const char* name)
Expand Down
4 changes: 2 additions & 2 deletions src/common/SurgeStorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
#include "ModulationSource.h"
#include "Wavetable.h"
#include <vector>
#include <thread/CriticalSection.h>
#include <memory>
#include <mutex>
#include <atomic>
#include <stdint.h>

Expand Down Expand Up @@ -857,7 +857,7 @@ class alignas(16) SurgeStorage
void storeMidiMappingToName( std::string name );

// float table_sin[512],table_sin_offset[512];
Surge::CriticalSection CS_WaveTableData, CS_ModRouting;
std::mutex waveTableDataMutex, modRoutingMutex;
Wavetable WindowWT;

float note_to_pitch(float x);
Expand Down
26 changes: 12 additions & 14 deletions src/common/SurgeSynthesizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2087,7 +2087,7 @@ float SurgeSynthesizer::getModulation(long ptag, modsources modsource)

void SurgeSynthesizer::clear_osc_modulation(int scene, int entry)
{
storage.CS_ModRouting.enter();
storage.modRoutingMutex.lock();
vector<ModulationRouting>::iterator iter;

int pid = storage.getPatch().scene[scene].osc[entry].p[0].param_id_in_scene;
Expand All @@ -2111,7 +2111,7 @@ void SurgeSynthesizer::clear_osc_modulation(int scene, int entry)
else
iter++;
}
storage.CS_ModRouting.leave();
storage.modRoutingMutex.unlock();
}

void SurgeSynthesizer::clearModulation(long ptag, modsources modsource, bool clearEvenIfInvalid)
Expand Down Expand Up @@ -2144,9 +2144,9 @@ void SurgeSynthesizer::clearModulation(long ptag, modsources modsource, bool cle
{
if ((modlist->at(i).destination_id == id) && (modlist->at(i).source_id == modsource))
{
storage.CS_ModRouting.enter();
storage.modRoutingMutex.lock();
modlist->erase(modlist->begin() + i);
storage.CS_ModRouting.leave();
storage.modRoutingMutex.unlock();
return;
}
}
Expand All @@ -2173,7 +2173,7 @@ bool SurgeSynthesizer::setModulation(long ptag, modsources modsource, float val)
modlist = &storage.getPatch().scene[scene - 1].modulation_voice;
}

storage.CS_ModRouting.enter();
storage.modRoutingMutex.lock();

int id = storage.getPatch().param_ptr[ptag]->param_id_in_scene;
if (!scene)
Expand Down Expand Up @@ -2211,7 +2211,7 @@ bool SurgeSynthesizer::setModulation(long ptag, modsources modsource, float val)
modlist->at(found_id).depth = value;
}
}
storage.CS_ModRouting.leave();
storage.modRoutingMutex.unlock();

return true;
}
Expand Down Expand Up @@ -2786,8 +2786,7 @@ void SurgeSynthesizer::process()
clear_block_antidenormalnoise(fxsendout[1][1], BLOCK_SIZE_QUAD);
}

// CS ENTER
storage.CS_ModRouting.enter();
storage.modRoutingMutex.lock();
processControl();

amp.set_target_smoothed(db_to_linear(storage.getPatch().volume.val.f));
Expand Down Expand Up @@ -2854,7 +2853,7 @@ void SurgeSynthesizer::process()
iter++;
}

storage.CS_ModRouting.leave();
storage.modRoutingMutex.unlock();

fbq_global g;
g.FU1ptr = GetQFPtrFilterUnit(storage.getPatch().scene[s].filterunit[0].type.val.i,
Expand Down Expand Up @@ -2895,11 +2894,10 @@ void SurgeSynthesizer::process()
v->GetQFB(); // save filter state in voices after quad processing is done
iter++;
}
storage.CS_ModRouting.enter();
storage.modRoutingMutex.lock();
}

// CS LEAVE
storage.CS_ModRouting.leave();
storage.modRoutingMutex.unlock();
polydisplay = vcount;

if (play_scene[0])
Expand Down Expand Up @@ -3136,7 +3134,7 @@ void SurgeSynthesizer::swapMetaControllers( int c1, int c2 )
strncpy( storage.getPatch().CustomControllerLabel[c1], storage.getPatch().CustomControllerLabel[c2], 16 );
strncpy( storage.getPatch().CustomControllerLabel[c2], nt, 16 );

storage.CS_ModRouting.enter();
storage.modRoutingMutex.lock();

auto tmp1 = storage.getPatch().scene[0].modsources[ms_ctrl1 + c1];
auto tmp2 = storage.getPatch().scene[0].modsources[ms_ctrl1 + c2];
Expand Down Expand Up @@ -3188,7 +3186,7 @@ void SurgeSynthesizer::swapMetaControllers( int c1, int c2 )
}
}

storage.CS_ModRouting.leave();
storage.modRoutingMutex.unlock();

refresh_editor = true;
}
Expand Down
6 changes: 2 additions & 4 deletions src/common/WavSupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -463,11 +463,9 @@ void SurgeStorage::load_wt_wav_portable(std::string fn, Wavetable *wt)

if( wavdata && wt )
{
CS_WaveTableData.enter();

waveTableDataMutex.lock();
wt->BuildWT(wavdata, wh, wh.flags & wtf_is_sample);

CS_WaveTableData.leave();
waveTableDataMutex.unlock();
free( wavdata );
}
return;
Expand Down
8 changes: 4 additions & 4 deletions src/common/gui/COscillatorDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,10 @@ void COscillatorDisplay::draw(CDrawContext* dc)
{
if (uses_wavetabledata(oscdata->type.val.i))
{
storage->CS_WaveTableData.enter();
storage->waveTableDataMutex.lock();
osc->process_block(disp_pitch_rs);
block_pos = 0;
storage->CS_WaveTableData.leave();
storage->waveTableDataMutex.unlock();
}
else
{
Expand Down Expand Up @@ -304,7 +304,7 @@ void COscillatorDisplay::draw(CDrawContext* dc)
rmenu.inset(14, 0);
char wttxt[256];

storage->CS_WaveTableData.enter();
storage->waveTableDataMutex.lock();

int wtid = oscdata->wt.current_id;
if( oscdata->wavetable_display_name[0] != '\0' )
Expand All @@ -324,7 +324,7 @@ void COscillatorDisplay::draw(CDrawContext* dc)
strcpy(wttxt, "(Patch Wavetable)");
}

storage->CS_WaveTableData.leave();
storage->waveTableDataMutex.unlock();

char* r = strrchr(wttxt, '.');
if (r)
Expand Down
18 changes: 10 additions & 8 deletions src/common/gui/SurgeGUIEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@
#include <stack>
#include <unordered_map>

#if WINDOWS
#include <windows.h>
#endif
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious why?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is for the definitions of SYSTEMTIME/GetSystemTime. Before, windows.h was included implicitly via SurgeStorage.hCriticalSection.h.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!
We should move that to std::chrono one day

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we actually didn't need the time at all so just cleaned it up and pushed


#if TARGET_VST3
#include "pluginterfaces/vst/ivstcontextmenu.h"
#include "pluginterfaces/base/ustring.h"
Expand Down Expand Up @@ -246,8 +250,6 @@ SurgeGUIEditor::SurgeGUIEditor(void* effect, SurgeSynthesizer* synth, void* user
_userdata = userdata;
this->synth = synth;

// ToolTipWnd = 0;

minimumZoom = 50;
#if LINUX
minimumZoom = 100; // See github issue #628
Expand Down Expand Up @@ -394,7 +396,7 @@ void SurgeGUIEditor::idle()
int ptag = ((CControl*)v)->getTag() - start_paramtags;
if (ptag >= 0)
{
synth->storage.CS_ModRouting.enter();
synth->storage.modRoutingMutex.lock();

for (int i = 1; i < n_modsources; i++)
{
Expand All @@ -403,19 +405,19 @@ void SurgeGUIEditor::idle()
->update_rt_vals(synth->isActiveModulation(ptag, (modsources)i), 0,
synth->isModsourceUsed((modsources)i));
}
synth->storage.CS_ModRouting.leave();
synth->storage.modRoutingMutex.unlock();
}
}
else
{
synth->storage.CS_ModRouting.enter();
synth->storage.modRoutingMutex.lock();
for (int i = 1; i < n_modsources; i++)
{
if( gui_modsrc[i] )
((CModulationSourceButton*)gui_modsrc[i])
->update_rt_vals(false, 0, synth->isModsourceUsed((modsources)i));
}
synth->storage.CS_ModRouting.leave();
synth->storage.modRoutingMutex.unlock();
}
#if MAC
idleinc++;
Expand Down Expand Up @@ -787,7 +789,7 @@ void SurgeGUIEditor::refresh_mod()
if( cms->hasAlternate && cms->useAlternate )
thisms = (modsources)cms->alternateId;

synth->storage.CS_ModRouting.enter();
synth->storage.modRoutingMutex.lock();
for (int i = 0; i < n_paramslots; i++)
{
if (param[i])
Expand Down Expand Up @@ -817,7 +819,7 @@ void SurgeGUIEditor::refresh_mod()
}
#endif

synth->storage.CS_ModRouting.leave();
synth->storage.modRoutingMutex.unlock();

for (int i = 1; i < n_modsources; i++)
{
Expand Down
4 changes: 0 additions & 4 deletions src/common/gui/SurgeGUIEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -368,10 +368,6 @@ class SurgeGUIEditor : public EditorType, public VSTGUI::IControlListener, publi
VSTGUI::CControl* lfodisplay = nullptr;
VSTGUI::CControl* filtersubtype[2] = {};
VSTGUI::CControl* fxmenu = nullptr;
#if MAC || LINUX
#else
HWND ToolTipWnd;
#endif
int clear_infoview_countdown = 0;
public:
int clear_infoview_peridle = -1;
Expand Down
40 changes: 0 additions & 40 deletions src/common/thread/CriticalSection.cpp

This file was deleted.

Loading