Add mutexes

This commit is contained in:
Jonas Kvinge
2024-09-02 22:27:45 +02:00
parent 2a9ccd7480
commit 552440f50e
6 changed files with 489 additions and 308 deletions

View File

@@ -1306,7 +1306,7 @@ void MainWindow::Exit() {
else {
if (app_->player()->engine()->is_fadeout_enabled()) {
// To shut down the application when fadeout will be finished
QObject::connect(&*app_->player()->engine(), &EngineBase::FadeoutFinishedSignal, this, &MainWindow::DoExit);
QObject::connect(&*app_->player()->engine(), &EngineBase::Finished, this, &MainWindow::DoExit);
if (app_->player()->GetState() == EngineBase::State::Playing) {
app_->player()->Stop();
ignore_close_ = true;

View File

@@ -0,0 +1,65 @@
/*
* Strawberry Music Player
* Copyright 2024, Jonas Kvinge <jonas@jkvinge.net>
*
* Strawberry 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 3 of the License, or
* (at your option) any later version.
*
* Strawberry 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 Strawberry. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef MUTEX_PROTECTED_H
#define MUTEX_PROTECTED_H
#include <boost/noncopyable.hpp>
#include <QMutex>
#include <QMutexLocker>
template<typename T>
class mutex_protected : public boost::noncopyable {
public:
mutex_protected(const mutex_protected &value) : value_(value.value()) {}
mutex_protected(const T value) : value_(value) {}
~mutex_protected() {}
T value() const {
QMutexLocker l(&mutex_);
return value_;
}
T operator==(const mutex_protected &value) const {
QMutexLocker l(&mutex_);
return value == value_;
}
T operator==(const T value) const {
QMutexLocker l(&mutex_);
return value == value_;
}
void operator=(const mutex_protected &value) {
QMutexLocker l(&mutex_);
value_ = value.value();
}
void operator=(const T value) {
QMutexLocker l(&mutex_);
value_ = value;
}
private:
T value_;
mutable QMutex mutex_;
};
#endif // MUTEX_PROTECTED_H