mirror of
https://foundry.openuru.org/gitblit/r/CWE-ou-minkata.git
synced 2025-07-18 11:19:10 +00:00
Reintroduce (and enforce use of) hsLockFor{Reading,Writing}
This commit is contained in:
@ -207,6 +207,7 @@ class hsReaderWriterLock
|
||||
public:
|
||||
hsReaderWriterLock() : fReaderCount(0), fWriterSem(1) { }
|
||||
|
||||
private:
|
||||
void LockForReading()
|
||||
{
|
||||
// Don't allow us to start reading if there's still an active writer
|
||||
@ -241,10 +242,44 @@ public:
|
||||
fReaderLock.unlock();
|
||||
}
|
||||
|
||||
private:
|
||||
std::atomic<int> fReaderCount;
|
||||
std::mutex fReaderLock;
|
||||
hsSemaphore fWriterSem;
|
||||
|
||||
friend class hsLockForReading;
|
||||
friend class hsLockForWriting;
|
||||
};
|
||||
|
||||
class hsLockForReading
|
||||
{
|
||||
hsReaderWriterLock& fLock;
|
||||
|
||||
public:
|
||||
hsLockForReading(hsReaderWriterLock& lock) : fLock(lock)
|
||||
{
|
||||
fLock.LockForReading();
|
||||
}
|
||||
|
||||
~hsLockForReading()
|
||||
{
|
||||
fLock.UnlockForReading();
|
||||
}
|
||||
};
|
||||
|
||||
class hsLockForWriting
|
||||
{
|
||||
hsReaderWriterLock& fLock;
|
||||
|
||||
public:
|
||||
hsLockForWriting(hsReaderWriterLock& lock) : fLock(lock)
|
||||
{
|
||||
fLock.LockForWriting();
|
||||
}
|
||||
|
||||
~hsLockForWriting()
|
||||
{
|
||||
fLock.UnlockForWriting();
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user