1
0
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:
2014-07-26 13:05:43 -07:00
parent 5836af7268
commit 474b54396b
3 changed files with 60 additions and 29 deletions

View File

@ -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