update MEF to preview 9
[mcs.git] / class / System.ComponentModel.Composition / src / Composition.Initialization / Microsoft / Internal / Lock.Writer.cs
blobe9d7088020f8280e7a19c09eb729dabddf41796b
1 // -----------------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation. All rights reserved.
3 // -----------------------------------------------------------------------
4 using System;
5 using System.Collections.Generic;
6 using System.Linq;
7 using System.Text;
8 using System.Threading;
10 namespace Microsoft.Internal
12 internal struct WriteLock : IDisposable
14 private readonly Lock _lock;
15 private int _isDisposed;
17 public WriteLock(Lock @lock)
19 this._isDisposed = 0;
20 this._lock = @lock;
21 this._lock.EnterWriteLock();
24 public void Dispose()
26 if (Interlocked.CompareExchange(ref this._isDisposed, 1, 0) == 0)
28 this._lock.ExitWriteLock();