Mutex.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. //
  2. // System.Threading.Mutex.cs
  3. //
  4. // Author:
  5. //
  6. // Dick Porter ([email protected])
  7. // Veronica De Santis ([email protected])
  8. //
  9. // (C) Ximian, Inc. http://www.ximian.com
  10. //
  11. using System;
  12. using System.Runtime.CompilerServices;
  13. namespace System.Threading
  14. {
  15. public sealed class Mutex : WaitHandle
  16. {
  17. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  18. private static extern IntPtr CreateMutex_internal(
  19. bool initiallyOwned,
  20. string name);
  21. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  22. private static extern void ReleaseMutex_internal(IntPtr handle);
  23. public Mutex() {
  24. os_handle=CreateMutex_internal(false,null);
  25. }
  26. public Mutex(bool initiallyOwned) {
  27. os_handle=CreateMutex_internal(initiallyOwned,null);
  28. }
  29. public Mutex(bool initiallyOwned, string name) {
  30. os_handle=CreateMutex_internal(initiallyOwned,name);
  31. }
  32. public Mutex(bool initiallyOwned, string name, out bool gotOwnership) {
  33. os_handle=CreateMutex_internal(initiallyOwned,name);
  34. gotOwnership=false;
  35. }
  36. public void ReleaseMutex() {
  37. ReleaseMutex_internal(os_handle);
  38. }
  39. }
  40. }