File: System\Threading\WriteLock.cs | Web Access |
Project: src\src\libraries\System.ComponentModel.Composition.Registration\src\System.ComponentModel.Composition.Registration.csproj (System.ComponentModel.Composition.Registration) |
// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. namespace System.Threading { internal struct WriteLock : IDisposable { private readonly ReadWriteLock _lock; private int _isDisposed; public WriteLock(ReadWriteLock @lock) { _isDisposed = 0; _lock = @lock; _lock.EnterWriteLock(); } public void Dispose() { if (Interlocked.CompareExchange(ref _isDisposed, 1, 0) == 0) { _lock.ExitWriteLock(); } } } } |