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() {
24 Handle = UnsafeNclNativeMethods.CreateSemaphore(IntPtr.Zero, initialCount, maxCount, IntPtr.Zero);
30 public Semaphore(int initialCount, int maxCount, string name) : base() {
38 internal bool ReleaseSemaphore() {
41 bool success = UnsafeNclNativeMethods.ReleaseSemaphore(Handle, 1, out previousCount);
42 GlobalLog.Print("ReleaseSemaphore#"+ValidationHelper.HashString(this)+" success:"+success+" previousCount:"+previousCount.ToString());
45 return UnsafeNclNativeMethods.ReleaseSemaphore(Handle, 1, IntPtr.Zero);
51 internal bool ReleaseSemaphore(int releaseCount, out int previousCount) {
52 return UnsafeNclNativeMethods.ReleaseSemaphore(Handle, releaseCount, out previousCount);