SRW locks are not loaded with tons of features like some of the other locks that Microsoft has to offer ; however, they fast and easy on the memory foot print. In fact, you can consider using SRW locks instead of ATL locking as a performance enhancement. I won’t get into SRW locks here, but you can read more about them on MSDN here:
The first thing to do is add a SRWLOCK member like so:
Then in your class’ constructor add the initialization:
Replace Lock() with this:
And Unlock() with this:
As you can see from the MSDN documentation SRW locks can do more than exclusive locks. You might want to look at these other SRW functions to give your critical sections just the right amount of protection.
The following are the SRW lock functions (from MSDN).
|SRW lock function||Description|
|AcquireSRWLockExclusive||Acquires an SRW lock in exclusive mode.|
|AcquireSRWLockShared||Acquires an SRW lock in shared mode.|
|InitializeSRWLock||Initialize an SRW lock.|
|ReleaseSRWLockExclusive||Releases an SRW lock that was opened in exclusive mode.|
|ReleaseSRWLockShared||Releases an SRW lock that was opened in shared mode.|
|SleepConditionVariableSRW||Sleeps on the specified condition variable and releases the specified lock as an atomic operation.|