Skip to content
Browse files

2002-01-16 Veronica De Santis <veron78@@interfree.it>

        * icall.h : Added the internal calls mapping for CreateMutex_internal
	  	    and ReleaseMutex_internal.

	* threads.h : Added the prototype of mutexes internal calls.

	* threads.c : Added the implementations of mutexes internal calls.

	* WaitHandle.cs : Renamed handle to os_handle and make it protected
	                  instead of private.
        * Mutex.cs : Write the System.Threading.Mutex methods ( constructors
              	     and the ReleaseMutex)

svn path=/trunk/mono/; revision=2010
  • Loading branch information...
1 parent 169190f commit 1222ab1b5c2642f4b9a1e3e16f73ce3ec8c4890a Veronica De Santis committed
Showing with 105 additions and 0 deletions.
  1. +6 −0 mono/metadata/ChangeLog
  2. +2 −0 mono/metadata/icall.c
  3. +8 −0 mono/metadata/threads.c
  4. +2 −0 mono/metadata/threads.h
  5. +87 −0 mono/tests/mutexes.cs
View
6 mono/metadata/ChangeLog
@@ -1,3 +1,9 @@
+2002-01-16 Veronica De Santis <veron78@@interfree.it>
+
+ * icall.h : Added the internal calls mapping for CreateMutex_internal
+ and ReleaseMutex_internal.
+ * threads.h : Added the prototype of mutexes internal calls.
+ * threads.c : Added the implementations of mutexes internal calls.
Tue Jan 15 22:47:57 CET 2002 Paolo Molaro <lupus@ximian.com>
View
2 mono/metadata/icall.c
@@ -864,6 +864,8 @@ static gpointer icall_map [] = {
"System.Threading.Monitor::Monitor_pulse_all", ves_icall_System_Threading_Monitor_Monitor_pulse_all,
"System.Threading.Monitor::Monitor_try_enter", ves_icall_System_Threading_Monitor_Monitor_try_enter,
"System.Threading.Monitor::Monitor_wait", ves_icall_System_Threading_Monitor_Monitor_wait,
+ "System.Threading.Mutex::CreateMutex_internal", ves_icall_System_Threading_Mutex_CreateMutex_internal,
+ "System.Threading.Mutex::ReleaseMutex_internal", ves_icall_System_Threading_Mutex_ReleaseMutex_internal,
/*
* System.Threading.WaitHandle
View
8 mono/metadata/threads.c
@@ -658,6 +658,14 @@ gboolean ves_icall_System_Threading_WaitHandle_WaitOne_internal(MonoObject *this
return(TRUE);
}
+WapiHandle *ves_icall_System_Threading_Mutex_CreateMutex_internal (MonoBoolean owned,char *name) {
+ return(CreateMutex(NULL,owned,name));
+}
+
+void ves_icall_System_Threading_Mutex_ReleaseMutex_internal (WapiHandle *handle ) {
+ ReleaseMutex(handle);
+}
+
void mono_thread_init(void)
{
View
2 mono/metadata/threads.h
@@ -31,6 +31,8 @@ extern gboolean ves_icall_System_Threading_Monitor_Monitor_test_synchronised(Mon
extern void ves_icall_System_Threading_Monitor_Monitor_pulse(MonoObject *obj);
extern void ves_icall_System_Threading_Monitor_Monitor_pulse_all(MonoObject *obj);
extern gboolean ves_icall_System_Threading_Monitor_Monitor_wait(MonoObject *obj, int ms);
+extern WapiHandle *ves_icall_System_Threading_Mutex_CreateMutex_internal(MonoBoolean owned,char *name);
+extern void ves_icall_System_Threading_Mutex_ReleaseMutex_internal(WapiHandle *handle);
extern gboolean ves_icall_System_Threading_WaitHandle_WaitAll_internal(MonoArray *mono_handles, gint32 ms, gboolean exitContext);
extern gint32 ves_icall_System_Threading_WaitHandle_WaitAny_internal(MonoArray *mono_handles, gint32 ms, gboolean exitContext);
View
87 mono/tests/mutexes.cs
@@ -0,0 +1,87 @@
+/////////////////////////////////// Test Overview ////////////////////////////////
+//
+// Two threads are started from Main, which allocates 10 static mutexes.
+// The first thread locks each mutex in turn, with a delay of 2000ms between
+// locks.
+// The second thread recursively locks mutex no. 5 10 times, blocking the
+// progress of the first thread as this second thread has a delay of 4500ms
+// between each lock.When the second thread has called ReleaseMutex on the mutex 10
+// times it terminates and the first thread can carry on its cycle of locking and
+// releasing mutexes until it exits.
+//
+/////////////////////////////////////////////////////////////////////////////////
+
+
+using System;
+using System.Threading;
+
+class MutexTest
+{
+ public static Mutex[] m;
+
+ // Code for first thread
+ public static void ThreadMethod_A()
+ {
+ Console.WriteLine("[Thread A] - Started.....");
+
+ for (int i=0;i<10;i++)
+ {
+ Console.WriteLine("[Thread A] - Trying to lock mutex "+i+"...");
+ m[i].WaitOne();
+ Console.WriteLine("[Thread A] - m["+i+"] Locked!");
+ Console.WriteLine("[Thread A] - Now using mutex ["+i+"]");
+ Thread.Sleep(2000);
+ m[i].ReleaseMutex();
+ Console.WriteLine("[Thread A] - Unlocked the mutex ["+i+"]");
+ }
+
+ Console.WriteLine("[Thread A] - exiting.....");
+ }
+
+ // Code for second thread
+ public static void ThreadMethod_B()
+ {
+ Console.WriteLine("[Thread B] - Started.....");
+
+ for (int h=0;h<10;h++)
+ {
+ int i=5;
+ Console.WriteLine("[Thread B] - Trying to lock mutex "+i+" for "+h+" time...");
+ m[i].WaitOne();
+ Console.WriteLine("[Thread B] - m["+i+"] Locked recursively ["+h+"] times!");
+ Thread.Sleep(4500);
+ }
+ for (int h=0;h<10;h++)
+ {
+ int i=5;
+ m[i].ReleaseMutex();
+ Console.WriteLine("[Thread B] - Unlocked the mutex ["+i+"] for ["+h+"] times");
+ }
+
+ Console.WriteLine("[Thread B] - Finished.....");
+ }
+
+
+ public static void Main()
+ {
+ m = new Mutex[10];
+ for (int i = 0 ; i<10 ; i++ )
+ m[i] = new Mutex();
+
+ // Create the first thread
+ Console.WriteLine("[ Main ] - Creating first thread..");
+ ThreadStart Thread_1 = new ThreadStart(ThreadMethod_A);
+
+ // Create the second thread
+ Console.WriteLine("[ Main ] - Creating second thread..");
+ ThreadStart Thread_2 = new ThreadStart(ThreadMethod_B);
+
+ Thread A = new Thread(Thread_1);
+ Thread B = new Thread(Thread_2);
+ A.Start();
+ B.Start();
+
+ Thread.Sleep(500);
+ Console.WriteLine("[ Main ] - Test Ended");
+ }
+}

0 comments on commit 1222ab1

Please sign in to comment.
Something went wrong with that request. Please try again.