/// <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); }
/// <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); }
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; } }
public ReadWriteLock(bool reentrant) { if (reentrant) { _wrapped = new ReentrantReadWriteLock(); } else { _wrapped = new NoReentrantReadWriteLock(); } }
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; }
public ReadWriteLock() { _wrapped = new NoReentrantReadWriteLock(); }
public ReadWriteLock(bool reentrant) { _wrapped = (IReadWriteLock)(reentrant ? (object)new ReentrantReadWriteLock() : new NoReentrantReadWriteLock()); }
public StudentDataSubstorage([NotNull] IReadWriteLock locker, [NotNull] IList <T> data) { Locker = locker; Data = data; }
public SmartWriteLock(IReadWriteLock lck) => @lock = lck;
public ProtectedResource() { _mylock = new ReadWriteLock(); Value = 5; }
public static void WriteUnlocker([NotNull] IReadWriteLock locker) => locker.ReleaseWriteLock();
public static void WriteLocker([NotNull] IReadWriteLock locker) => locker.AcquireWriteLock();