update MEF to preview 9
[mcs.git] / class / System.ComponentModel.Composition / src / Composition.Initialization / Microsoft / Internal / Lock.Reader.cs
blob3f81a68ade982da5012dfc6c2480036fa4b5c8ad
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 ReadLock : IDisposable
14 private readonly Lock _lock;
15 private int _isDisposed;
17 public ReadLock(Lock @lock)
19 this._isDisposed = 0;
20 this._lock = @lock;
21 this._lock.EnterReadLock();
24 public void Dispose()
26 if (Interlocked.CompareExchange(ref this._isDisposed, 1, 0) == 0)
28 this._lock.ExitReadLock();