Пример #1
0
        /// <summary>
        ///   Use this lock instance.
        ///   Any options objects originating from this options object will use this same lock!
        ///   It is generally not necessary to call this method, unless you want to create such a shared lock.
        /// </summary>
        /// <seealso cref="ReadWriteLock" />
        /// <returns>New options with the lock set to this lock instance</returns>
        public PlaneDBOptions UsingLock(IReadWriteLock readWriteLock)
        {
            var rv = Clone();

            rv.ReadWriteLock = readWriteLock ?? throw new ArgumentNullException(nameof(readWriteLock));
            return(rv);
        }
Пример #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SmartReadWriteLock"/> class.
        /// </summary>
        /// <param name="lck">Read write lock </param>
        public SmartReadWriteLock(IReadWriteLock lck)
        {
            if (lck == null)
            {
                throw new ArgumentNullException("lck");
            }

            readLock  = new SmartReadLock(lck);
            writeLock = new SmartWriteLock(lck);
        }
Пример #3
0
 public ReadWriteTest(int readCount, int writeCount, IReadWriteLock readWriteLock)
 {
     this.readCount     = readCount;
     this.writeCount    = writeCount;
     this.readWriteLock = readWriteLock;
     data = new int[10];
     for (int i = 0; i < data.Length; i++)
     {
         data[i] = 0;
     }
 }
Пример #4
0
 public ReadWriteLock(bool reentrant)
 {
     if (reentrant)
     {
         _wrapped = new ReentrantReadWriteLock();
     }
     else
     {
         _wrapped = new NoReentrantReadWriteLock();
     }
 }
Пример #5
0
 public ReadWriteLock(bool reentrant)
 {
     if (reentrant)
     {
         _wrapped = new ReentrantReadWriteLock();
     }
     else
     {
         _wrapped = new NoReentrantReadWriteLock();
     }
 }
Пример #6
0
        internal PlaneDBState(DirectoryInfo location, FileMode mode, PlaneDBOptions options)
        {
            this.location = location;
            this.options  = options;
            ReadWriteLock = options.ThreadSafe ? options.TrueReadWriteLock : new FakeReadWriteLock();

            try {
                lockFile = mode switch {
                    FileMode.CreateNew => new FileStream(Manifest.FindFile(location, options, Manifest.LOCK_FILE).FullName,
                                                         FileMode.CreateNew, FileAccess.ReadWrite,
                                                         FileShare.None),
                    FileMode.Open => new FileStream(Manifest.FindFile(location, options, Manifest.LOCK_FILE).FullName,
                                                    FileMode.Create, FileAccess.ReadWrite,
                                                    FileShare.None),
                    FileMode.OpenOrCreate => new FileStream(Manifest.FindFile(location, options, Manifest.LOCK_FILE).FullName,
                                                            FileMode.Create, FileAccess.ReadWrite,
                                                            FileShare.None),
                    _ => throw new ArgumentOutOfRangeException(nameof(mode), mode, null)
                };
            }
            catch (UnauthorizedAccessException ex) {
                throw new AlreadyLockedException(ex);
            }
            catch (IOException ex) {
                throw new AlreadyLockedException(ex);
            }

            // ReSharper disable once ConvertSwitchStatementToSwitchExpression
            switch (mode)
            {
            case FileMode.CreateNew:
            case FileMode.Open:
            case FileMode.OpenOrCreate:
                Manifest = new Manifest(location, mode, options);
                break;

            case FileMode.Append:
            case FileMode.Create:
            case FileMode.Truncate:
                throw new NotSupportedException(nameof(mode));

            default:
                throw new ArgumentOutOfRangeException(nameof(mode), mode, null);
            }

            Manifest.RemoveOrphans();
            MaybeReplayJournal(Manifest);

            Journal = OpenJournal();
        }
 public GlobalLockExamSystem([NotNull] IReadWriteLock locker, [NotNull] ILogger logger)
 {
     Locker = locker;
     Logger = logger;
 }
Пример #8
0
 public ReadWriteLock()
 {
     _wrapped = new NoReentrantReadWriteLock();
 }
Пример #9
0
 public ReadWriteLock(bool reentrant)
 {
     _wrapped = (IReadWriteLock)(reentrant ? (object)new ReentrantReadWriteLock() : new NoReentrantReadWriteLock());
 }
Пример #10
0
 public ReadWriteLock()
 {
     _wrapped = new NoReentrantReadWriteLock();
 }
Пример #11
0
 public StudentDataSubstorage([NotNull] IReadWriteLock locker, [NotNull] IList <T> data)
 {
     Locker = locker;
     Data   = data;
 }
Пример #12
0
 public SmartWriteLock(IReadWriteLock lck) => @lock = lck;
Пример #13
0
 public ProtectedResource()
 {
     _mylock = new ReadWriteLock();
     Value   = 5;
 }
Пример #14
0
 public static void WriteUnlocker([NotNull] IReadWriteLock locker) => locker.ReleaseWriteLock();
Пример #15
0
 public static void WriteLocker([NotNull] IReadWriteLock locker) => locker.AcquireWriteLock();