From 42953944da1261584d56405128c6eb3c0e9e7da0 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Sun, 1 May 2016 21:36:04 +0200 Subject: The last loader thread stuff. --- src/midimapper.cc | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'src/midimapper.cc') diff --git a/src/midimapper.cc b/src/midimapper.cc index 05f69e5..ab3d8d7 100644 --- a/src/midimapper.cc +++ b/src/midimapper.cc @@ -28,20 +28,26 @@ int MidiMapper::lookup(int note) { + std::lock_guard guard(mutex); + if(midimap.find(note) == midimap.end()) { return -1; } - std::string instr = midimap[note]; + + const std::string& instr = midimap[note]; if(instrmap.find(instr) == instrmap.end()) { return -1; } + return instrmap[instr]; } -void MidiMapper::clear() +void MidiMapper::swap(instrmap_t& instrmap, midimap_t& midimap) { - midimap.clear(); - instrmap.clear(); + std::lock_guard guard(mutex); + + std::swap(this->instrmap, instrmap); + std::swap(this->midimap, midimap); } -- cgit v1.2.3