Merge pull request #757 from mlintner/master
[mono.git] / mcs / class / System.Web.Mvc3 / Mvc / Async / SingleEntryGate.cs
1 namespace System.Web.Mvc.Async {
2     using System;
3     using System.Threading;
4
5     // used to synchronize access to a single-use consumable resource
6     internal sealed class SingleEntryGate {
7
8         private const int NOT_ENTERED = 0;
9         private const int ENTERED = 1;
10
11         private int _status;
12
13         // returns true if this is the first call to TryEnter(), false otherwise
14         public bool TryEnter() {
15             int oldStatus = Interlocked.Exchange(ref _status, ENTERED);
16             return (oldStatus == NOT_ENTERED);
17         }
18
19     }
20 }