The Labs \ Source Viewer \ SSCLI \ System.Net \ Semaphore

  1. //------------------------------------------------------------------------------
  2. // <copyright file="Semaphore.cs" company="Microsoft">
  3. //
  4. // Copyright (c) 2006 Microsoft Corporation. All rights reserved.
  5. //
  6. // The use and distribution terms for this software are contained in the file
  7. // named license.txt, which can be found in the root of this distribution.
  8. // By using this software in any fashion, you are agreeing to be bound by the
  9. // terms of this license.
  10. //
  11. // You must not remove this notice, or any other, from this software.
  12. //
  13. // </copyright>
  14. //------------------------------------------------------------------------------
  15. #pragma warning disable 618
  16. namespace System.Net
  17. {
  18.    
  19.    
  20.     using System;
  21.     using System.Threading;
  22.     using System.Security.Permissions;
  23.    
  24.    
  25.     // used for Connection Pooling
  26.     internal sealed class Semaphore : WaitHandle
  27.     {
  28.         internal Semaphore(int initialCount, int maxCount) : base()
  29.         {
  30.             lock (this) {
  31.                 Handle = UnsafeNclNativeMethods.CreateSemaphore(IntPtr.Zero, initialCount, maxCount, IntPtr.Zero);
  32.             }
  33.         }
  34.        
  35. /*
  36.         //                                   
  37.         public Semaphore(int initialCount, int maxCount, string name) : base() {
  38.             lock (this) {
  39.                 //                                                                         
  40.                 Handle = UnsafeNclNativeMethods.CreateSemaphore(IntPtr.Zero, initialCount, maxCount, name);
  41.             }
  42.         }
  43.         */       
  44.        
  45.         internal bool ReleaseSemaphore()
  46.         {
  47.             #if DEBUG
  48.             int previousCount;
  49.             bool success = UnsafeNclNativeMethods.ReleaseSemaphore(Handle, 1, out previousCount);
  50.             GlobalLog.Print("ReleaseSemaphore#" + ValidationHelper.HashString(this) + " success:" + success + " previousCount:" + previousCount.ToString());
  51.             return success;
  52.             #else
  53.             return UnsafeNclNativeMethods.ReleaseSemaphore(Handle, 1, IntPtr.Zero);
  54.             #endif
  55.         }
  56.        
  57.         /*
  58.         //                                   
  59.         internal bool ReleaseSemaphore(int releaseCount, out int previousCount) {
  60.             return UnsafeNclNativeMethods.ReleaseSemaphore(Handle, releaseCount, out previousCount);       
  61.         }
  62.         */       
  63.     }
  64. }

Developer Fusion