[m-dev.] for review: semaphore.m working in hlc.gc grade

Peter Ross peter.ross at miscrit.be
Tue Nov 7 03:13:55 AEDT 2000


Hi,


===================================================================


Estimated hours taken: 0.5

semaphore.m:
    When compiling semaphore in the hlc.gc grade make all the operations
    no-ops.  This allows us to use the mutvar module in the hlc.gc
    grade.

spawn.m:
    Issue an error if we try and compile this module in the hlc.gc
    grade.


Index: semaphore.m
===================================================================
RCS file: /home/mercury1/repository/mercury/extras/concurrency/semaphore.m,v
retrieving revision 1.6
diff -u -r1.6 semaphore.m
--- semaphore.m	2000/09/18 09:06:53	1.6
+++ semaphore.m	2000/11/06 16:10:27
@@ -10,9 +10,6 @@
 % This module implements a simple semaphore data type for allowing
 % coroutines to synchronise with one another.
 %
-% Note if you are compiling in a hlc grade, the grade component must
-% contain a `.par'.
-%
 %---------------------------------------------------------------------------%
 :- module semaphore.
 
@@ -54,10 +51,6 @@
 :- type semaphore	== c_pointer.
 
 :- pragma c_header_code("
-#if defined(MR_HIGHLEVEL_CODE) && !defined(MR_THREAD_SAFE)
-  #error Semaphores only work in the hlc.par.* or non-hlc grades.
-#endif
-
 	#include <stdio.h>
 	#include ""mercury_context.h""
 	#include ""mercury_thread.h""
@@ -67,7 +60,9 @@
 #ifndef MR_HIGHLEVEL_CODE
 		MR_Context	*suspended;
 #else
+  #ifdef MR_THREAD_SAFE
 		MercuryCond	cond;
+  #endif 
 #endif
 #ifdef MR_THREAD_SAFE
 		MercuryLock	lock;
@@ -92,7 +87,9 @@
 #ifndef MR_HIGHLEVEL_CODE
 	sem->suspended = NULL;
 #else
+  #ifdef MR_THREAD_SAFE
 	pthread_cond_init(&(sem->cond), MR_COND_ATTR);
+  #endif
 #endif
 #ifdef MR_THREAD_SAFE
 	pthread_mutex_init(&(sem->lock), MR_MUTEX_ATTR);
@@ -119,10 +116,10 @@
 
 	sem = (ME_Semaphore *) obj;
 
-  #ifdef MR_HIGHLEVEL_CODE
-	pthread_cond_destroy(&(sem->cond));
-  #endif
   #ifdef MR_THREAD_SAFE
+    #ifdef MR_HIGHLEVEL_CODE
+	pthread_cond_destroy(&(sem->cond));
+    #endif
 	pthread_mutex_destroy(&(sem->lock));
   #endif
 
Index: spawn.m
===================================================================
RCS file: /home/mercury1/repository/mercury/extras/concurrency/spawn.m,v
retrieving revision 1.4
diff -u -r1.4 spawn.m
--- spawn.m	2000/09/08 09:14:55	1.4
+++ spawn.m	2000/11/06 16:10:27
@@ -38,6 +38,10 @@
 :- implementation.
 
 :- pragma c_header_code("
+#if defined(MR_HIGHLEVEL_CODE) && !defined(MR_THREAD_SAFE)
+  #error The spawn module requires either hlc.par.gc grade or a non-hlc grade.
+#endif
+
 	#include <stdio.h>
 ").
 

--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list