Tue Sep 10 12:12:51 CEST 2002 Paolo Molaro <lupus@ximian.com>
[mono.git] / mcs / class / corlib / System.Threading / Mutex.cs
1 //
2 // System.Threading.Mutex.cs
3 //
4 // Author:
5 //
6 //   Dick Porter (dick@ximian.com)
7 //   Veronica De Santis (veron78@interfree.it)
8 //
9 // (C) Ximian, Inc.  http://www.ximian.com
10 //
11
12 using System;
13 using System.Runtime.CompilerServices;
14
15 namespace System.Threading
16 {
17         public sealed class Mutex : WaitHandle 
18         {
19                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
20                 private static extern IntPtr  CreateMutex_internal(
21                                                          bool initiallyOwned,
22                                                          string name);
23
24                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
25                 private static extern void ReleaseMutex_internal(IntPtr handle);
26
27                 public Mutex() {
28                         os_handle=CreateMutex_internal(false,null);
29                 }
30                 
31                 public Mutex(bool initiallyOwned) {
32                         os_handle=CreateMutex_internal(initiallyOwned,null);
33                 }
34
35                 public Mutex(bool initiallyOwned, string name) {                                
36                         os_handle=CreateMutex_internal(initiallyOwned,name);    
37                 }
38         
39
40                 public Mutex(bool initiallyOwned, string name, out bool gotOwnership) {
41                         os_handle=CreateMutex_internal(initiallyOwned,name);
42                         gotOwnership=false;
43                 }
44         
45                 public void ReleaseMutex() {
46                         ReleaseMutex_internal(os_handle);
47                 }
48         }
49 }