public GlobalReaderWriterLock(string nameOfThisLock)
{
_hatName = nameOfThisLock;
// we need to make two native sync objects, a mutex and a semaphore
// that are global so every process and user on the system can share them as long as they agree on the lock's name
string mutexId = string.Format("Global\\Mut_{0}", _hatName);
string semaphoreId = string.Format("Global\\Sem_{0}", _hatName);
bool iDontCareWhetherItsNew;
{
MutexAccessRule allowEveryoneRule = new MutexAccessRule(new SecurityIdentifier(WellKnownSidType.WorldSid, null), MutexRights.FullControl, AccessControlType.Allow);
MutexSecurity securitySettings = new MutexSecurity();
securitySettings.AddAccessRule(allowEveryoneRule);
_holdTheHat = new Mutex(false, mutexId, out iDontCareWhetherItsNew, securitySettings);
}
{
SemaphoreAccessRule allowEveryoneRule = new SemaphoreAccessRule(new SecurityIdentifier(WellKnownSidType.WorldSid, null), SemaphoreRights.FullControl, AccessControlType.Allow);
SemaphoreSecurity securitySettings = new SemaphoreSecurity();
securitySettings.AddAccessRule(allowEveryoneRule);
_chipsInTheHat = new Semaphore(READER_CHIPS, READER_CHIPS, semaphoreId, out iDontCareWhetherItsNew, securitySettings);
}
}