MISC 2: Make ReferenceCounter refcount itself protected by the same mutex of the whole class, for state consistency

This commit is contained in:
vsonnier 2016-06-01 19:46:45 +02:00
parent 357dcc967b
commit fc4fa3e74f
4 changed files with 14 additions and 8 deletions

View File

@ -21,21 +21,27 @@ struct map_string_less : public std::binary_function<std::string,std::string,boo
class ReferenceCounter {
public:
mutable std::mutex m_mutex;
void setRefCount(int rc) {
refCount.store(rc);
std::lock_guard < std::recursive_mutex > lock(m_mutex);
refCount = rc;
}
void decRefCount() {
refCount.store(refCount.load()-1);
std::lock_guard < std::recursive_mutex > lock(m_mutex);
refCount--;
}
int getRefCount() {
return refCount.load();
std::lock_guard < std::recursive_mutex > lock(m_mutex);
return refCount;
}
protected:
std::atomic_int refCount;
//this is a basic mutex for all ReferenceCounter derivatives operations INCLUDING the counter itself for consistency !
mutable std::recursive_mutex m_mutex;
private:
int refCount;
};

View File

@ -28,7 +28,7 @@ public:
}
~AudioThreadInput() {
std::lock_guard < std::mutex > lock(m_mutex);
std::lock_guard < std::recursive_mutex > lock(m_mutex);
}
};

View File

@ -90,7 +90,7 @@ public:
}
~DemodulatorThreadPostIQData() {
std::lock_guard < std::mutex > lock(m_mutex);
std::lock_guard < std::recursive_mutex > lock(m_mutex);
}
};

View File

@ -32,7 +32,7 @@ public:
}
~ModemIQData() {
std::lock_guard < std::mutex > lock(m_mutex);
std::lock_guard < std::recursive_mutex > lock(m_mutex);
}
};