Exemple #1
0
        static void NamedReaderWriterLocker(NamedStatefulObject namedStatefulObject)
        {
            var interactionType = GetInteractionType();
            var rwLock          = _namedReaderWriterLocker.GetLock(namedStatefulObject.UniqueName);

            try
            {
                if (interactionType == InteractionType.Read)
                {
                    rwLock.EnterReadLock();
                    namedStatefulObject.ReadState();
                }
                else
                {
                    rwLock.EnterWriteLock();
                    namedStatefulObject.ChangeState();
                }
            }
            finally
            {
                if (interactionType == InteractionType.Read)
                {
                    rwLock.ExitReadLock();
                }
                else
                {
                    rwLock.ExitWriteLock();
                }
            }
        }
Exemple #2
0
 static void NamedLocker(NamedStatefulObject namedStatefulObject)
 {
     lock (_namedlocker.GetLock(namedStatefulObject.UniqueName))
     {
         if (GetInteractionType() == InteractionType.Read)
         {
             namedStatefulObject.ReadState();
         }
         else
         {
             namedStatefulObject.ChangeState();
         }
     }
 }
Exemple #3
0
 static void InternedString(NamedStatefulObject namedStatefulObject)
 {
     lock (string.Intern(namedStatefulObject.UniqueName))
     {
         if (GetInteractionType() == InteractionType.Read)
         {
             namedStatefulObject.ReadState();
         }
         else
         {
             namedStatefulObject.ChangeState();
         }
     }
 }
Exemple #4
0
 static void FullBlownResourceLock(NamedStatefulObject namedStatefulObject)
 {
     lock (_fullBlownResourceLocker)
     {
         if (GetInteractionType() == InteractionType.Read)
         {
             namedStatefulObject.ReadState();
         }
         else
         {
             namedStatefulObject.ChangeState();
         }
     }
 }
Exemple #5
0
        static void NamedMutex(NamedStatefulObject namedStatefulObject)
        {
            //here a mutex is broadcast to the entire OS. Handy to share a named lock cross process but slow.
            //oh yeah, make sure to pick a unique name!
            using (var mutex = new Mutex(false, namedStatefulObject.UniqueName))
            {
                mutex.WaitOne();

                if (GetInteractionType() == InteractionType.Read)
                {
                    namedStatefulObject.ReadState();
                }
                else
                {
                    namedStatefulObject.ChangeState();
                }

                mutex.ReleaseMutex();
            }
        }