Exemplo n.º 1
0
        public static ReadWriteLock Lock(ReaderWriterLockSlim locker, ReadWriteLockMode mode)
        {
            var readWriteLocker = new ReadWriteLock(locker, mode);

            switch (mode)
            {
            case ReadWriteLockMode.Read:
                if (!locker.TryEnterReadLock(DefaultTimeoutInMs))
                {
                    throw new LockTimeoutException(mode);
                }
                break;

            case ReadWriteLockMode.Write:
                if (!locker.TryEnterWriteLock(DefaultTimeoutInMs))
                {
                    throw new LockTimeoutException(mode);
                }
                break;

            case ReadWriteLockMode.UpgradeableRead:
                if (!locker.TryEnterUpgradeableReadLock(DefaultTimeoutInMs))
                {
                    throw new LockTimeoutException(mode);
                }
                break;
            }

            return(readWriteLocker);
        }
Exemplo n.º 2
0
 private ReadWriteLock(ReaderWriterLockSlim locker, ReadWriteLockMode mode) : this()
 {
     this.locker = locker;
     this.mode   = mode;
 }
Exemplo n.º 3
0
 public LockTimeoutException(ReadWriteLockMode mode)
     : base(string.Format("Timeout waiting for '{0}' mode", mode.ToString()))
 {
 }