From 6e461de50e73c0c957af73e5ee7a25f4d0293490 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Tue, 26 Mar 2024 12:23:51 +0100 Subject: Make all mutex locks const, as per linter warning --- src/atomic.h | 20 ++++++++++---------- src/audiocacheeventhandler.cc | 6 +++--- src/audiocacheidmanager.cc | 10 +++++----- src/audiofile.cc | 4 ++-- src/drumgizmo.cc | 2 +- src/drumkitloader.cc | 10 +++++----- src/midimapper.cc | 4 ++-- src/syncedsettings.h | 16 ++++++++-------- src/translation.cc | 8 ++++---- 9 files changed, 40 insertions(+), 40 deletions(-) diff --git a/src/atomic.h b/src/atomic.h index 7ca5d1e..a29eeee 100644 --- a/src/atomic.h +++ b/src/atomic.h @@ -69,7 +69,7 @@ public: : data{} , mutex{} { - std::lock_guard lock{other.mutex}; + const std::lock_guard lock{other.mutex}; data = other.data; } @@ -77,13 +77,13 @@ public: : data{} , mutex{} { - std::lock_guard lock{other.mutex}; + const std::lock_guard lock{other.mutex}; std::swap(data, other.data); } T operator=(T data) { - std::lock_guard lock{mutex}; + const std::lock_guard lock{mutex}; this->data = std::move(data); return this->data; } @@ -100,42 +100,42 @@ public: void store(T data) { - std::lock_guard lock{mutex}; + const std::lock_guard lock{mutex}; this->data = std::move(data); } T load() const { - std::lock_guard lock{mutex}; + const std::lock_guard lock{mutex}; return data; } T exchange(T data){ - std::lock_guard lock{mutex}; + const std::lock_guard lock{mutex}; std::swap(data, this->data); return data; } bool operator==(const T& other) const { - std::lock_guard lock{mutex}; + const std::lock_guard lock{mutex}; return other == data; } bool operator!=(const T& other) const { - std::lock_guard lock{mutex}; + const std::lock_guard lock{mutex}; return !(other == data); } bool operator==(const Atomic& other) const { - std::lock_guard lock{mutex}; + const std::lock_guard lock{mutex}; return other.load() == data; } bool operator!=(const Atomic& other) const { - std::lock_guard lock{mutex}; + const std::lock_guard lock{mutex}; return !(other.load() == data); } diff --git a/src/audiocacheeventhandler.cc b/src/audiocacheeventhandler.cc index e1b9868..06bbf6e 100644 --- a/src/audiocacheeventhandler.cc +++ b/src/audiocacheeventhandler.cc @@ -179,7 +179,7 @@ size_t AudioCacheEventHandler::getChunkSize() const AudioCacheFile& AudioCacheEventHandler::openFile(const std::string& filename) { - std::lock_guard lock(mutex); + const std::lock_guard lock(mutex); return files.getFile(filename); } @@ -207,7 +207,7 @@ void AudioCacheEventHandler::handleLoadNextEvent(CacheEvent& cache_event) void AudioCacheEventHandler::handleCloseEvent(CacheEvent& cache_event) { - std::lock_guard lock(mutex); + const std::lock_guard lock(mutex); handleCloseCache(cache_event.id); } @@ -272,7 +272,7 @@ void AudioCacheEventHandler::pushEvent(CacheEvent& cache_event) } { - std::lock_guard lock(mutex); + const std::lock_guard lock(mutex); bool found = false; diff --git a/src/audiocacheidmanager.cc b/src/audiocacheidmanager.cc index 91a1457..693ed3c 100644 --- a/src/audiocacheidmanager.cc +++ b/src/audiocacheidmanager.cc @@ -37,7 +37,7 @@ AudioCacheIDManager::~AudioCacheIDManager() void AudioCacheIDManager::init(unsigned int capacity) { - std::lock_guard guard(mutex); + const std::lock_guard guard(mutex); id2cache.resize(capacity); available_ids.resize(capacity); @@ -49,7 +49,7 @@ void AudioCacheIDManager::init(unsigned int capacity) cache_t& AudioCacheIDManager::getCache(cacheid_t id) { - std::lock_guard guard(mutex); + const std::lock_guard guard(mutex); assert(id != CACHE_NOID); assert(id != CACHE_DUMMYID); @@ -62,7 +62,7 @@ cache_t& AudioCacheIDManager::getCache(cacheid_t id) cacheid_t AudioCacheIDManager::registerID(const cache_t& cache) { - std::lock_guard guard(mutex); + const std::lock_guard guard(mutex); cacheid_t id = CACHE_NOID; @@ -86,7 +86,7 @@ cacheid_t AudioCacheIDManager::registerID(const cache_t& cache) void AudioCacheIDManager::releaseID(cacheid_t id) { - std::lock_guard guard(mutex); + const std::lock_guard guard(mutex); assert(id2cache[id].id != CACHE_NOID); // Test if it wasn't already released. @@ -97,7 +97,7 @@ void AudioCacheIDManager::releaseID(cacheid_t id) void AudioCacheIDManager::disableActive() { - // Run through all active cache_ts and disable them. + // Run through all active CacheBuffers and disable them. for(auto& cache : id2cache) { if(cache.id != CACHE_NOID) diff --git a/src/audiofile.cc b/src/audiofile.cc index 2d61eb5..3f59fcf 100644 --- a/src/audiofile.cc +++ b/src/audiofile.cc @@ -61,7 +61,7 @@ bool AudioFile::isValid() const void AudioFile::unload() { // Make sure we don't unload the object while loading it... - std::lock_guard guard(mutex); + const std::lock_guard guard(mutex); is_loaded = false; @@ -76,7 +76,7 @@ void AudioFile::unload() void AudioFile::load(LogFunction logger, std::size_t sample_limit) { // Make sure we don't unload the object while loading it... - std::lock_guard guard(mutex); + const std::lock_guard guard(mutex); if(this->data) // already loaded { diff --git a/src/drumgizmo.cc b/src/drumgizmo.cc index bd729ab..85624ca 100644 --- a/src/drumgizmo.cc +++ b/src/drumgizmo.cc @@ -391,7 +391,7 @@ void DrumGizmo::getSamples(int ch, int pos, sample_t* s, size_t sz) { // TODO: We should make all audiofiles reference counted and get rid of this lock. - std::lock_guard guard(af.mutex); + const std::lock_guard guard(af.mutex); renderSampleEvent(sample_event, pos, s, sz); diff --git a/src/drumkitloader.cc b/src/drumkitloader.cc index 9167201..d73efff 100644 --- a/src/drumkitloader.cc +++ b/src/drumkitloader.cc @@ -93,7 +93,7 @@ void DrumKitLoader::deinit() framesize_semaphore.post(); { - std::lock_guard guard(mutex); + const std::lock_guard guard(mutex); load_queue.clear(); } @@ -301,13 +301,13 @@ void DrumKitLoader::loadKitAudio(const DrumKit& kit) void DrumKitLoader::skip() { - std::lock_guard guard(mutex); + const std::lock_guard guard(mutex); load_queue.clear(); } void DrumKitLoader::setFrameSize(std::size_t framesize) { - std::lock_guard guard(mutex); + const std::lock_guard guard(mutex); this->framesize = framesize; framesize_semaphore.post(); // Signal that the framesize has been set. } @@ -324,7 +324,7 @@ void DrumKitLoader::thread_main() { std::size_t size; { - std::lock_guard guard(mutex); + const std::lock_guard guard(mutex); size = load_queue.size(); } @@ -367,7 +367,7 @@ void DrumKitLoader::thread_main() std::string filename; { - std::lock_guard guard(mutex); + const std::lock_guard guard(mutex); if(load_queue.size() == 0) { diff --git a/src/midimapper.cc b/src/midimapper.cc index b9316c5..345ce2f 100644 --- a/src/midimapper.cc +++ b/src/midimapper.cc @@ -30,7 +30,7 @@ std::vector MidiMapper::lookup(int note_id) { std::vector instruments; - std::lock_guard guard(mutex); + const std::lock_guard guard(mutex); for(const auto& map_entry : midimap) { @@ -49,7 +49,7 @@ std::vector MidiMapper::lookup(int note_id) void MidiMapper::swap(instrmap_t& instrmap, midimap_t& midimap) { - std::lock_guard guard(mutex); + const std::lock_guard guard(mutex); std::swap(this->instrmap, instrmap); std::swap(this->midimap, midimap); diff --git a/src/syncedsettings.h b/src/syncedsettings.h index 0fe5efd..d12277a 100644 --- a/src/syncedsettings.h +++ b/src/syncedsettings.h @@ -64,7 +64,7 @@ public: : mutex{} , data{} { - std::lock_guard lock{other.mutex}; + const std::lock_guard lock{other.mutex}; data = other.data; } @@ -72,7 +72,7 @@ public: : mutex{} , data{} { - std::lock_guard lock{other.mutex}; + const std::lock_guard lock{other.mutex}; std::swap(data, other.data); } @@ -80,19 +80,19 @@ public: { if (*this != &other) { - std::lock_guard lock{mutex}; - std::lock_guard lock2{other.mutex}; + const std::lock_guard lock{mutex}; + const std::lock_guard lock2{other.mutex}; data = other.data; } return *this; } - + Group& operator=(Group&& other) { if (*this != &other) { - std::lock_guard lock{mutex}; - std::lock_guard lock2{other.mutex}; + const std::lock_guard lock{mutex}; + const std::lock_guard lock2{other.mutex}; std::swap(data, other.data); } return *this; @@ -100,7 +100,7 @@ public: operator T() const { - std::lock_guard lock{mutex}; + const std::lock_guard lock{mutex}; return data; } }; diff --git a/src/translation.cc b/src/translation.cc index 18763e4..c71f6c0 100644 --- a/src/translation.cc +++ b/src/translation.cc @@ -62,13 +62,13 @@ bool comparator(const Text& a, const Text& b) Translation::Translation() { - std::lock_guard(singleton.mutex); + const std::lock_guard lock(singleton.mutex); ++singleton.refcnt; } Translation::~Translation() { - std::lock_guard(singleton.mutex); + const std::lock_guard lock(singleton.mutex); --singleton.refcnt; @@ -219,7 +219,7 @@ bool Translation::load(const char* catalog, std::size_t size) std::sort(texts.begin(), texts.end(), comparator); { - std::lock_guard(singleton.mutex); + const std::lock_guard lock(singleton.mutex); std::swap(singleton.texts, texts); } @@ -228,7 +228,7 @@ bool Translation::load(const char* catalog, std::size_t size) const char* Translation::gettext(std::uint64_t msgid, const char* original) { - std::lock_guard(singleton.mutex); + const std::lock_guard lock(singleton.mutex); if(singleton.refcnt == 0) { return original; -- cgit v1.2.3