update MEF to preview 9
[mcs.git] / class / System.ComponentModel.Composition / src / ComponentModel / Microsoft / Internal / Lock.cs
blob7cd7ac2ee5e9ea47536cb91be2c0e01131f652cb
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 sealed class Lock : IDisposable
14 #if (!SILVERLIGHT)
15 private ReaderWriterLockSlim _thisLock = new ReaderWriterLockSlim(LockRecursionPolicy.NoRecursion);
16 private int _isDisposed = 0;
17 public void EnterReadLock()
19 this._thisLock.EnterReadLock();
22 public void EnterWriteLock()
24 this._thisLock.EnterWriteLock();
27 public void ExitReadLock()
29 this._thisLock.ExitReadLock();
32 public void ExitWriteLock()
34 this._thisLock.ExitWriteLock();
37 public void Dispose()
39 if (Interlocked.CompareExchange(ref this._isDisposed, 1, 0) == 0)
41 this._thisLock.Dispose();
45 #else
46 // ReaderWriterLockSlim is not yet implemented on SilverLight
47 // Satisfies our requirements until it is implemented
48 object _thisLock = new object();
50 public Lock()
54 public void EnterReadLock()
56 Monitor.Enter(this._thisLock);
59 public void EnterWriteLock()
61 Monitor.Enter(this._thisLock);
64 public void ExitReadLock()
66 Monitor.Exit(this._thisLock);
69 public void ExitWriteLock()
71 Monitor.Exit(this._thisLock);
74 public void Dispose()
77 #endif