[m-rev.] for review: update concurrency library

Peter Wang wangp at students.csse.unimelb.edu.au
Wed Sep 13 14:10:49 AEST 2006


Followup to the patch I posted yesterday.

Estimated hours taken: 1
Branches: main

extras/concurrency/semaphore.m:
extras/concurrency/spawn.m:
	Update these two modules for the newer parallel execution mechanism
	in the low level C grades:

	- rename MR_schedule to MR_schedule_context;
	
	- set MR_ENGINE(MR_eng_this_context) to NULL before calling
	  MR_runnext().  MR_do_runnext() now assumes that any context pointed
	  to by the Mercury engine can be clobbered or reused.

extras/concurrency/Mmakefile:
extras/concurrency/Mercury.options:
	Disable `--thread-local-engine-base' for spawn.m and semaphore.m as the
	hand-written code is not written to cope with that option.

	Move compiler flags into Mercury.options so they are picked up by
	`mmc --make' as well.

Index: extras/concurrency/Mercury.options
===================================================================
RCS file: extras/concurrency/Mercury.options
diff -N extras/concurrency/Mercury.options
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ extras/concurrency/Mercury.options	13 Sep 2006 03:56:25 -0000
@@ -0,0 +1,11 @@
+MCFLAGS-concurrency += --no-warn-nothing-exported --no-warn-interface-imports
+
+# In parallel, low level C grades that don't reserve a machine register for
+# the engine base (i.e. don't use gcc global registers) don't generate code
+# that assumes we cache the engine base address into a local variable
+# MR_local_thread_engine_base.  These two modules contain hand-written code
+# which jump about a bit and maintaining MR_local_thread_engine_base in all
+# the right places is tricky (i.e. I gave up).
+#
+MCFLAGS-spawn += --no-local-thread-engine-base
+MCFLAGS-semaphore += --no-local-thread-engine-base
Index: extras/concurrency/Mmakefile
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/extras/concurrency/Mmakefile,v
retrieving revision 1.7
diff -u -r1.7 Mmakefile
--- extras/concurrency/Mmakefile	20 Apr 2006 07:32:05 -0000	1.7
+++ extras/concurrency/Mmakefile	13 Sep 2006 04:06:54 -0000
@@ -9,6 +9,7 @@
 TESTS = philo philo2 philo3 midimon
 
 -include ../Mmake.params
+include Mercury.options
 
 default_target: all
 
@@ -19,8 +20,6 @@
 realclean:	concurrency.realclean $(TESTS:%=%.realclean)
 tests:		$(TESTS)
 
-MCFLAGS-concurrency+=--no-warn-nothing-exported --no-warn-interface-imports
-
 .PHONY: check
 check: all
 		true
Index: extras/concurrency/semaphore.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/extras/concurrency/semaphore.m,v
retrieving revision 1.16
diff -u -r1.16 semaphore.m
--- extras/concurrency/semaphore.m	15 Aug 2006 04:19:38 -0000	1.16
+++ extras/concurrency/semaphore.m	13 Sep 2006 03:51:29 -0000
@@ -185,12 +185,13 @@
         ctxt = sem->suspended;
         sem->suspended = ctxt->MR_ctxt_next;
         MR_UNLOCK(&(sem->lock), ""semaphore__signal"");
-        MR_schedule(ctxt);
+        MR_schedule_context(ctxt);
             /* yield() */
         MR_save_context(MR_ENGINE(MR_eng_this_context));
         MR_ENGINE(MR_eng_this_context)->MR_ctxt_resume =
             &&signal_skip_to_the_end_1;
-        MR_schedule(MR_ENGINE(MR_eng_this_context));
+        MR_schedule_context(MR_ENGINE(MR_eng_this_context));
+        MR_ENGINE(MR_eng_this_context) = NULL;
         MR_runnext();
 signal_skip_to_the_end_1: ;
     } else {
@@ -200,7 +201,8 @@
         MR_save_context(MR_ENGINE(MR_eng_this_context));
         MR_ENGINE(MR_eng_this_context)->MR_ctxt_resume =
             &&signal_skip_to_the_end_2;
-        MR_schedule(MR_ENGINE(MR_eng_this_context));
+        MR_schedule_context(MR_ENGINE(MR_eng_this_context));
+        MR_ENGINE(MR_eng_this_context) = NULL;
         MR_runnext();
 signal_skip_to_the_end_2: ;
     }
@@ -254,6 +256,7 @@
         MR_ENGINE(MR_eng_this_context)->MR_ctxt_next = sem->suspended;
         sem->suspended = MR_ENGINE(MR_eng_this_context);
         MR_UNLOCK(&(sem->lock), ""semaphore__wait"");
+        MR_ENGINE(MR_eng_this_context) = NULL;
         MR_runnext();
 wait_skip_to_the_end: ;
     }
Index: extras/concurrency/spawn.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/extras/concurrency/spawn.m,v
retrieving revision 1.15
diff -u -r1.15 spawn.m
--- extras/concurrency/spawn.m	31 Aug 2006 11:09:49 -0000	1.15
+++ extras/concurrency/spawn.m	13 Sep 2006 03:52:12 -0000
@@ -66,13 +66,14 @@
         /* Store the closure on the top of the new context's stack. */
     *(ctxt->MR_ctxt_sp) = Goal;
     ctxt->MR_ctxt_next = NULL;
-    MR_schedule(ctxt);
+    MR_schedule_context(ctxt);
     if (0) {
 spawn_call_back_to_mercury_cc_multi:
         MR_save_registers();
             /* Get the closure from the top of the stack */
         call_back_to_mercury_cc_multi(*((MR_Word *)MR_sp));
         MR_destroy_context(MR_ENGINE(MR_eng_this_context));
+        MR_ENGINE(MR_eng_this_context) = NULL;
         MR_runnext();
     }
 #else
@@ -102,7 +103,8 @@
     MR_save_context(MR_ENGINE(MR_eng_this_context));
     MR_ENGINE(MR_eng_this_context)->MR_ctxt_resume =
         &&yield_skip_to_the_end;
-    MR_schedule(MR_ENGINE(MR_eng_this_context));
+    MR_schedule_context(MR_ENGINE(MR_eng_this_context));
+    MR_ENGINE(MR_eng_this_context) = NULL;
     MR_runnext();
 yield_skip_to_the_end:
 #endif
--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the reviews mailing list