using System; using System.IO; using System.Runtime.CompilerServices; using System.Runtime.ConstrainedExecution; using System.Runtime.InteropServices; using System.Security.AccessControl; namespace System.Threading { /// Limits the number of threads that can access a resource or pool of resources concurrently. /// 1 // Token: 0x020002EB RID: 747 [ComVisible(false)] public sealed class Semaphore : WaitHandle { // Token: 0x06001B21 RID: 6945 RVA: 0x00063B64 File Offset: 0x00061D64 private Semaphore(IntPtr handle) { this.Handle = handle; } /// Initializes a new instance of the class, specifying the maximum number of concurrent entries and optionally reserving some entries. /// The initial number of requests for the semaphore that can be granted concurrently. /// The maximum number of requests for the semaphore that can be granted concurrently. /// /// is greater than . /// /// is less than 1.-or- is less than 0. // Token: 0x06001B22 RID: 6946 RVA: 0x00063B74 File Offset: 0x00061D74 public Semaphore(int initialCount, int maximumCount) : this(initialCount, maximumCount, null) { } /// Initializes a new instance of the class, specifying the maximum number of concurrent entries, optionally reserving some entries for the calling thread, and optionally specifying the name of a system semaphore object. /// The initial number of requests for the semaphore that can be granted concurrently. /// The maximum number of requests for the semaphore that can be granted concurrently. /// The name of a named system semaphore object. /// /// is greater than .-or- is longer than 260 characters. /// /// is less than 1.-or- is less than 0. /// A Win32 error occurred. /// The named semaphore exists and has access control security, and the user does not have . /// The named semaphore cannot be created, perhaps because a wait handle of a different type has the same name. // Token: 0x06001B23 RID: 6947 RVA: 0x00063B80 File Offset: 0x00061D80 public Semaphore(int initialCount, int maximumCount, string name) { if (initialCount < 0) { throw new ArgumentOutOfRangeException("initialCount", "< 0"); } if (maximumCount < 1) { throw new ArgumentOutOfRangeException("maximumCount", "< 1"); } if (initialCount > maximumCount) { throw new ArgumentException("initialCount > maximumCount"); } bool flag; this.Handle = Semaphore.CreateSemaphore_internal(initialCount, maximumCount, name, out flag); } /// Initializes a new instance of the class, specifying the maximum number of concurrent entries, optionally reserving some entries for the calling thread, optionally specifying the name of a system semaphore object, and specifying a variable that receives a value indicating whether a new system semaphore was created. /// The initial number of requests for the semaphore that can be satisfied concurrently. /// The maximum number of requests for the semaphore that can be satisfied concurrently. /// The name of a named system semaphore object. /// When this method returns, contains true if a local semaphore was created (that is, if is null or an empty string) or if the specified named system semaphore was created; false if the specified named system semaphore already existed. This parameter is passed uninitialized. /// /// is greater than . -or- is longer than 260 characters. /// /// is less than 1.-or- is less than 0. /// A Win32 error occurred. /// The named semaphore exists and has access control security, and the user does not have . /// The named semaphore cannot be created, perhaps because a wait handle of a different type has the same name. // Token: 0x06001B24 RID: 6948 RVA: 0x00063BE4 File Offset: 0x00061DE4 public Semaphore(int initialCount, int maximumCount, string name, out bool createdNew) : this(initialCount, maximumCount, name, out createdNew, null) { } /// Initializes a new instance of the class, specifying the maximum number of concurrent entries, optionally reserving some entries for the calling thread, optionally specifying the name of a system semaphore object, specifying a variable that receives a value indicating whether a new system semaphore was created, and specifying security access control for the system semaphore. /// The initial number of requests for the semaphore that can be satisfied concurrently. /// The maximum number of requests for the semaphore that can be satisfied concurrently. /// The name of a named system semaphore object. /// When this method returns, contains true if a local semaphore was created (that is, if is null or an empty string) or if the specified named system semaphore was created; false if the specified named system semaphore already existed. This parameter is passed uninitialized. /// A object that represents the access control security to be applied to the named system semaphore. /// /// is greater than .-or- is longer than 260 characters. /// /// is less than 1.-or- is less than 0. /// The named semaphore exists and has access control security, and the user does not have . /// A Win32 error occurred. /// The named semaphore cannot be created, perhaps because a wait handle of a different type has the same name. // Token: 0x06001B25 RID: 6949 RVA: 0x00063BF4 File Offset: 0x00061DF4 [global::System.MonoTODO("Does not support access control, semaphoreSecurity is ignored")] public Semaphore(int initialCount, int maximumCount, string name, out bool createdNew, global::System.Security.AccessControl.SemaphoreSecurity semaphoreSecurity) { if (initialCount < 0) { throw new ArgumentOutOfRangeException("initialCount", "< 0"); } if (maximumCount < 1) { throw new ArgumentOutOfRangeException("maximumCount", "< 1"); } if (initialCount > maximumCount) { throw new ArgumentException("initialCount > maximumCount"); } this.Handle = Semaphore.CreateSemaphore_internal(initialCount, maximumCount, name, out createdNew); } // Token: 0x06001B26 RID: 6950 [MethodImpl(MethodImplOptions.InternalCall)] private static extern IntPtr CreateSemaphore_internal(int initialCount, int maximumCount, string name, out bool createdNew); // Token: 0x06001B27 RID: 6951 [MethodImpl(MethodImplOptions.InternalCall)] private static extern int ReleaseSemaphore_internal(IntPtr handle, int releaseCount, out bool fail); // Token: 0x06001B28 RID: 6952 [MethodImpl(MethodImplOptions.InternalCall)] private static extern IntPtr OpenSemaphore_internal(string name, global::System.Security.AccessControl.SemaphoreRights rights, out global::System.IO.MonoIOError error); /// Gets the access control security for a named system semaphore. /// A object that represents the access control security for the named system semaphore. /// The current object represents a named system semaphore, and the user does not have rights.-or-The current object represents a named system semaphore and was not opened with rights. /// Not supported for Windows 98 or Windows Millennium Edition. /// 1 // Token: 0x06001B29 RID: 6953 RVA: 0x00063C58 File Offset: 0x00061E58 [global::System.MonoTODO] public global::System.Security.AccessControl.SemaphoreSecurity GetAccessControl() { throw new NotImplementedException(); } /// Exits the semaphore and returns the previous count. /// The count on the semaphore before the method was called. /// The semaphore count is already at the maximum value. /// A Win32 error occurred with a named semaphore. /// The current semaphore represents a named system semaphore, but the user does not have .-or-The current semaphore represents a named system semaphore, but it was not opened with . /// 1 // Token: 0x06001B2A RID: 6954 RVA: 0x00063C60 File Offset: 0x00061E60 [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)] [PrePrepareMethod] public int Release() { return this.Release(1); } /// Exits the semaphore a specified number of times and returns the previous count. /// The count on the semaphore before the method was called. /// The number of times to exit the semaphore. /// /// is less than 1. /// The semaphore count is already at the maximum value. /// A Win32 error occurred with a named semaphore. /// The current semaphore represents a named system semaphore, but the user does not have rights.-or-The current semaphore represents a named system semaphore, but it was not opened with rights. /// 1 // Token: 0x06001B2B RID: 6955 RVA: 0x00063C6C File Offset: 0x00061E6C [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)] public int Release(int releaseCount) { if (releaseCount < 1) { throw new ArgumentOutOfRangeException("releaseCount"); } bool flag; int num = Semaphore.ReleaseSemaphore_internal(this.Handle, releaseCount, out flag); if (flag) { throw new SemaphoreFullException(); } return num; } /// Sets the access control security for a named system semaphore. /// A object that represents the access control security to be applied to the named system semaphore. /// /// is null. /// The user does not have rights.-or-The semaphore was not opened with rights. /// The current object does not represent a named system semaphore. /// 1 // Token: 0x06001B2C RID: 6956 RVA: 0x00063CA8 File Offset: 0x00061EA8 [global::System.MonoTODO] public void SetAccessControl(global::System.Security.AccessControl.SemaphoreSecurity semaphoreSecurity) { if (semaphoreSecurity == null) { throw new ArgumentNullException("semaphoreSecurity"); } throw new NotImplementedException(); } /// Opens an existing named semaphore. /// A object that represents a named system semaphore. /// The name of a named system semaphore. /// /// is an empty string.-or- is longer than 260 characters. /// /// is null. /// The named semaphore does not exist. /// A Win32 error occurred. /// The named semaphore exists, but the user does not have the security access required to use it. /// 1 /// /// /// // Token: 0x06001B2D RID: 6957 RVA: 0x00063CC0 File Offset: 0x00061EC0 public static Semaphore OpenExisting(string name) { return Semaphore.OpenExisting(name, global::System.Security.AccessControl.SemaphoreRights.Modify | global::System.Security.AccessControl.SemaphoreRights.Synchronize); } /// Opens an existing named semaphore, specifying the desired security access rights. /// A object that represents the named system semaphore. /// The name of a system semaphore. /// A bitwise combination of the values that represent the desired security access rights. /// /// is an empty string.-or- is longer than 260 characters. /// /// is null. /// The named semaphore does not exist. /// A Win32 error occurred. /// The named semaphore exists, but the user does not have the desired security access rights. /// 1 // Token: 0x06001B2E RID: 6958 RVA: 0x00063CD0 File Offset: 0x00061ED0 public static Semaphore OpenExisting(string name, global::System.Security.AccessControl.SemaphoreRights rights) { if (name == null) { throw new ArgumentNullException("name"); } if (name.Length == 0 || name.Length > 260) { throw new ArgumentException("name", global::Locale.GetText("Invalid length [1-260].")); } global::System.IO.MonoIOError monoIOError; IntPtr intPtr = Semaphore.OpenSemaphore_internal(name, rights, out monoIOError); if (!(intPtr == (IntPtr)null)) { return new Semaphore(intPtr); } if (monoIOError == global::System.IO.MonoIOError.ERROR_FILE_NOT_FOUND) { throw new WaitHandleCannotBeOpenedException(global::Locale.GetText("Named Semaphore handle does not exist: ") + name); } if (monoIOError == global::System.IO.MonoIOError.ERROR_ACCESS_DENIED) { throw new UnauthorizedAccessException(); } throw new IOException(global::Locale.GetText("Win32 IO error: ") + monoIOError.ToString()); } } }