mutex_protected: Add more operators

This commit is contained in:
Jonas Kvinge
2025-01-15 07:00:16 +01:00
parent d0bf2d7a9c
commit 92f34ff36e

View File

@@ -47,6 +47,56 @@ class mutex_protected : public boost::noncopyable {
return value == value_;
}
bool operator!=(const mutex_protected &value) const {
QMutexLocker l(&mutex_);
return value.value() != value_;
}
bool operator!=(const T value) const {
QMutexLocker l(&mutex_);
return value != value_;
}
bool operator>(const mutex_protected &value) const {
QMutexLocker l(&mutex_);
return value_ > value.value();
}
bool operator>(const T value) const {
QMutexLocker l(&mutex_);
return value_ > value;
}
bool operator>=(const mutex_protected &value) const {
QMutexLocker l(&mutex_);
return value_ >= value.value();
}
bool operator>=(const T value) const {
QMutexLocker l(&mutex_);
return value_ >= value;
}
bool operator<(const mutex_protected &value) const {
QMutexLocker l(&mutex_);
return value_ < value.value();
}
bool operator<(const T value) const {
QMutexLocker l(&mutex_);
return value_ < value;
}
bool operator<=(const mutex_protected &value) const {
QMutexLocker l(&mutex_);
return value_ <= value.value();
}
bool operator<=(const T value) const {
QMutexLocker l(&mutex_);
return value_ <= value;
}
void operator=(const mutex_protected &value) {
QMutexLocker l(&mutex_);
value_ = value.value();
@@ -62,11 +112,31 @@ class mutex_protected : public boost::noncopyable {
++value_;
}
void operator+=(const T value) {
QMutexLocker l(&mutex_);
value_ += value;
}
void operator+=(const mutex_protected value) {
QMutexLocker l(&mutex_);
value_ += value.value();
}
void operator--() {
QMutexLocker l(&mutex_);
--value_;
}
void operator-=(const T value) {
QMutexLocker l(&mutex_);
value_ -= value;
}
void operator-=(const mutex_protected value) {
QMutexLocker l(&mutex_);
value_ -= value.value();
}
private:
T value_;
mutable QMutex mutex_;