Semaphore.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. //
  2. // System.Threading.Semaphore.cs
  3. //
  4. // Author:
  5. // Sebastien Pouliot <[email protected]>
  6. //
  7. // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
  8. //
  9. // Permission is hereby granted, free of charge, to any person obtaining
  10. // a copy of this software and associated documentation files (the
  11. // "Software"), to deal in the Software without restriction, including
  12. // without limitation the rights to use, copy, modify, merge, publish,
  13. // distribute, sublicense, and/or sell copies of the Software, and to
  14. // permit persons to whom the Software is furnished to do so, subject to
  15. // the following conditions:
  16. //
  17. // The above copyright notice and this permission notice shall be
  18. // included in all copies or substantial portions of the Software.
  19. //
  20. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  21. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  22. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  23. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  24. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  25. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  26. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  27. //
  28. #if NET_2_0
  29. using System.Runtime.ConstrainedExecution;
  30. using System.Runtime.InteropServices;
  31. using System.Security.AccessControl;
  32. namespace System.Threading {
  33. [ComVisible (false)]
  34. [MonoTODO ("not supported by the runtime")]
  35. public sealed class Semaphore : WaitHandle {
  36. [MonoTODO]
  37. public Semaphore (int initialCount, int maximumCount)
  38. : this (initialCount, maximumCount, null)
  39. {
  40. }
  41. [MonoTODO]
  42. public Semaphore (int initialCount, int maximumCount, string name)
  43. {
  44. if (initialCount < 0)
  45. throw new ArgumentOutOfRangeException ("initialCount", "< 0");
  46. if (maximumCount < 1)
  47. throw new ArgumentOutOfRangeException ("maximumCount", "< 1");
  48. if (initialCount > maximumCount)
  49. throw new ArgumentException ("initialCount > maximumCount");
  50. throw new NotImplementedException ();
  51. }
  52. [MonoTODO]
  53. public Semaphore (int initialCount, int maximumCount, string name, out bool createdNew)
  54. : this (initialCount, maximumCount, name, out createdNew, null)
  55. {
  56. }
  57. [MonoTODO]
  58. public Semaphore (int initialCount, int maximumCount, string name, out bool createdNew,
  59. SemaphoreSecurity semaphoreSecurity)
  60. {
  61. if (initialCount < 0)
  62. throw new ArgumentOutOfRangeException ("initialCount", "< 0");
  63. if (maximumCount < 1)
  64. throw new ArgumentOutOfRangeException ("maximumCount", "< 1");
  65. if (initialCount > maximumCount)
  66. throw new ArgumentException ("initialCount > maximumCount");
  67. createdNew = false;
  68. throw new NotImplementedException ();
  69. }
  70. [MonoTODO]
  71. public SemaphoreSecurity GetAccessControl ()
  72. {
  73. throw new NotImplementedException ();
  74. }
  75. [MonoTODO]
  76. [PrePrepareMethod]
  77. [ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
  78. public int Release ()
  79. {
  80. throw new NotImplementedException ();
  81. }
  82. [MonoTODO]
  83. [ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
  84. public int Release (int releaseCount)
  85. {
  86. if (releaseCount < 1)
  87. throw new ArgumentOutOfRangeException ("releaseCount");
  88. throw new NotImplementedException ();
  89. }
  90. [MonoTODO]
  91. public void SetAccessControl (SemaphoreSecurity semaphoreSecurity)
  92. {
  93. if (semaphoreSecurity == null)
  94. throw new ArgumentNullException ("semaphoreSecurity");
  95. throw new NotImplementedException ();
  96. }
  97. // static methods
  98. public static Semaphore OpenExisting (string name)
  99. {
  100. return OpenExisting (name, SemaphoreRights.Synchronize | SemaphoreRights.Modify);
  101. }
  102. [MonoTODO]
  103. public static Semaphore OpenExisting (string name, SemaphoreRights rights)
  104. {
  105. if (name == null)
  106. throw new ArgumentNullException ("name");
  107. if ((name.Length ==0) || (name.Length > 260))
  108. throw new ArgumentException ("name", Locale.GetText ("Invalid length [1-260]."));
  109. throw new NotImplementedException ();
  110. }
  111. }
  112. }
  113. #endif