Adding reference source for System.Net
[mono.git] / mcs / class / referencesource / System / net / System / Net / _Semaphore.cs
1 //------------------------------------------------------------------------------
2 // <copyright file="Semaphore.cs" company="Microsoft">
3 //     Copyright (c) Microsoft Corporation.  All rights reserved.
4 // </copyright>                                                                
5 //------------------------------------------------------------------------------
6
7 #pragma warning disable 618
8
9 namespace System.Net 
10 {  
11
12
13         using System;
14         using System.Threading;
15     using System.Security.Permissions;
16
17
18     // used for Connection Pooling
19     internal sealed class Semaphore : WaitHandle
20     {
21         internal Semaphore(int initialCount, int maxCount) : base() {
22             lock (this) {
23                 // 
24                 Handle = UnsafeNclNativeMethods.CreateSemaphore(IntPtr.Zero, initialCount, maxCount, IntPtr.Zero);
25             }
26         }
27
28         /*
29         // Consider removing.
30         public Semaphore(int initialCount, int maxCount, string name) : base() {
31             lock (this) {
32                 // 
33
34
35
36 */
37
38         internal bool ReleaseSemaphore() {
39 #if DEBUG        
40             int previousCount;
41             bool success = UnsafeNclNativeMethods.ReleaseSemaphore(Handle, 1, out previousCount);        
42             GlobalLog.Print("ReleaseSemaphore#"+ValidationHelper.HashString(this)+" success:"+success+" previousCount:"+previousCount.ToString());
43             return success;
44 #else            
45             return UnsafeNclNativeMethods.ReleaseSemaphore(Handle, 1, IntPtr.Zero);
46 #endif            
47         }
48
49         /*
50         // Consider removing.
51         internal bool ReleaseSemaphore(int releaseCount, out int previousCount) {
52             return UnsafeNclNativeMethods.ReleaseSemaphore(Handle, releaseCount, out previousCount);        
53         }
54         */
55     }
56 }