Merge pull request #3142 from henricm/fix-for-win-mono_string_to_utf8
[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 #if MONO
24                 int errorCode;
25                 Handle = System.Threading.Semaphore.CreateSemaphore_internal(initialCount, maxCount, null, out errorCode);
26 #else
27                 // 
28                 Handle = UnsafeNclNativeMethods.CreateSemaphore(IntPtr.Zero, initialCount, maxCount, IntPtr.Zero);
29 #endif
30             }
31         }
32
33         /*
34         // Consider removing.
35         public Semaphore(int initialCount, int maxCount, string name) : base() {
36             lock (this) {
37                 // 
38
39
40
41 */
42
43         internal bool ReleaseSemaphore() {
44 #if MONO
45             int previousCount;
46             return System.Threading.Semaphore.ReleaseSemaphore_internal (Handle, 1, out previousCount);
47 #else
48 #if DEBUG
49             int previousCount;
50             bool success = UnsafeNclNativeMethods.ReleaseSemaphore(Handle, 1, out previousCount);        
51             GlobalLog.Print("ReleaseSemaphore#"+ValidationHelper.HashString(this)+" success:"+success+" previousCount:"+previousCount.ToString());
52             return success;
53 #else            
54             return UnsafeNclNativeMethods.ReleaseSemaphore(Handle, 1, IntPtr.Zero);
55 #endif
56 #endif
57         }
58
59         /*
60         // Consider removing.
61         internal bool ReleaseSemaphore(int releaseCount, out int previousCount) {
62             return UnsafeNclNativeMethods.ReleaseSemaphore(Handle, releaseCount, out previousCount);        
63         }
64         */
65     }
66 }