mirror of
https://github.com/cjcliffe/CubicSDR.git
synced 2024-11-25 13:18:37 -05:00
MISC 2: Make ReferenceCounter refcount itself protected by the same mutex of the whole class, for state consistency
This commit is contained in:
parent
357dcc967b
commit
fc4fa3e74f
@ -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;
|
||||
};
|
||||
|
||||
|
||||
|
@ -28,7 +28,7 @@ public:
|
||||
}
|
||||
|
||||
~AudioThreadInput() {
|
||||
std::lock_guard < std::mutex > lock(m_mutex);
|
||||
std::lock_guard < std::recursive_mutex > lock(m_mutex);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -90,7 +90,7 @@ public:
|
||||
}
|
||||
|
||||
~DemodulatorThreadPostIQData() {
|
||||
std::lock_guard < std::mutex > lock(m_mutex);
|
||||
std::lock_guard < std::recursive_mutex > lock(m_mutex);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -32,7 +32,7 @@ public:
|
||||
}
|
||||
|
||||
~ModemIQData() {
|
||||
std::lock_guard < std::mutex > lock(m_mutex);
|
||||
std::lock_guard < std::recursive_mutex > lock(m_mutex);
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user