mirror of
https://github.com/cjcliffe/CubicSDR.git
synced 2025-02-03 09:44:26 -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 {
|
class ReferenceCounter {
|
||||||
public:
|
public:
|
||||||
mutable std::mutex m_mutex;
|
|
||||||
|
|
||||||
void setRefCount(int rc) {
|
void setRefCount(int rc) {
|
||||||
refCount.store(rc);
|
std::lock_guard < std::recursive_mutex > lock(m_mutex);
|
||||||
|
refCount = rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
void decRefCount() {
|
void decRefCount() {
|
||||||
refCount.store(refCount.load()-1);
|
std::lock_guard < std::recursive_mutex > lock(m_mutex);
|
||||||
|
refCount--;
|
||||||
}
|
}
|
||||||
|
|
||||||
int getRefCount() {
|
int getRefCount() {
|
||||||
return refCount.load();
|
std::lock_guard < std::recursive_mutex > lock(m_mutex);
|
||||||
|
return refCount;
|
||||||
}
|
}
|
||||||
protected:
|
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() {
|
~AudioThreadInput() {
|
||||||
std::lock_guard < std::mutex > lock(m_mutex);
|
std::lock_guard < std::recursive_mutex > lock(m_mutex);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -90,7 +90,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
~DemodulatorThreadPostIQData() {
|
~DemodulatorThreadPostIQData() {
|
||||||
std::lock_guard < std::mutex > lock(m_mutex);
|
std::lock_guard < std::recursive_mutex > lock(m_mutex);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
~ModemIQData() {
|
~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