I am providing a thin wrapper around a non-thread safe map using AcquireSRWLockShared and AcquireSRWLockExclusive Windows APIs. Essentially, lookup related methods are taking a read lock and "set" related methods are taking a write lock -- simple enough, straight forward.
Here is the wrinkle: I am refactoring old code and one of the requirements is that the caller needs to be able to lock this map at the "collection level" and then make different calls into it -- all "under one transaction" so to speak.
The problem is that if I was to take a Write lock and hold on to it, then if I was to do a Lookup -- the Lookup method is attempting to take a read lock which will fail or block. It seems like I am jamming 2 different approaches into one basket and its just not happening.
The only workaround I can think of is that I should be using a plain critical section which does not differentiate between readers and writers -- and the same thread can enter the same critical section multiple times. That would suck because I really want to get single writer / multiple readers performance. Any ideas?