1 //------------------------------------------------------------------------------
2 // <copyright file="Semaphore.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
5 //------------------------------------------------------------------------------
7 #pragma warning disable 618
14 using System.Threading;
15 using System.Security.Permissions;
18 // used for Connection Pooling
19 internal sealed class Semaphore : WaitHandle
21 internal Semaphore(int initialCount, int maxCount) : base() {
25 Handle = System.Threading.Semaphore.CreateSemaphore_internal(initialCount, maxCount, null, out errorCode);
28 Handle = UnsafeNclNativeMethods.CreateSemaphore(IntPtr.Zero, initialCount, maxCount, IntPtr.Zero);
35 public Semaphore(int initialCount, int maxCount, string name) : base() {
43 internal bool ReleaseSemaphore() {
46 return System.Threading.Semaphore.ReleaseSemaphore_internal (Handle, 1, out previousCount);
50 bool success = UnsafeNclNativeMethods.ReleaseSemaphore(Handle, 1, out previousCount);
51 GlobalLog.Print("ReleaseSemaphore#"+ValidationHelper.HashString(this)+" success:"+success+" previousCount:"+previousCount.ToString());
54 return UnsafeNclNativeMethods.ReleaseSemaphore(Handle, 1, IntPtr.Zero);
61 internal bool ReleaseSemaphore(int releaseCount, out int previousCount) {
62 return UnsafeNclNativeMethods.ReleaseSemaphore(Handle, releaseCount, out previousCount);