[m-dev.] diff/for review: changes to runtime

Fergus Henderson fjh at cs.mu.OZ.AU
Mon Jun 15 17:19:28 AEST 1998


On 15-Jun-1998, Fergus Henderson <fjh at cs.mu.OZ.AU> wrote:
> 
> Tom, can you please review these changes?

Forgot the diff again, doh!

cvs diff: Diffing .
Index: mercury_context.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_context.c,v
retrieving revision 1.4
diff -u -u -r1.4 mercury_context.c
--- mercury_context.c	1998/06/09 02:07:49	1.4
+++ mercury_context.c	1998/06/11 21:42:20
@@ -22,14 +22,14 @@
 #include "mercury_context.h"
 #include "mercury_engine.h"	/* for `memdebug' */
 
-Context		*MR_runqueue;
+MR_Context	*MR_runqueue;
 #ifdef	MR_THREAD_SAFE
   MercuryLock	*MR_runqueue_lock;
   MercuryCond	*MR_runqueue_cond;
 #endif
 
 
-static Context	*free_context_list = NULL;
+static MR_Context *free_context_list = NULL;
 #ifdef	MR_THREAD_SAFE
   static	MercuryLock *free_context_list_lock;
 #endif
@@ -64,7 +64,7 @@
 }
 
 void 
-init_context(Context *c)
+init_context(MR_Context *c)
 {
 	c->next = NULL;
 	c->resume = NULL;
@@ -111,15 +111,15 @@
 	c->context_hp = NULL;
 }
 
-Context *
+MR_Context *
 create_context(void)
 {
-	Context *c;
+	MR_Context *c;
 
 	MR_LOCK(free_context_list_lock, "create_context");
 	if (free_context_list == NULL) {
 		MR_UNLOCK(free_context_list_lock, "create_context i");
-		c = (Context *) make(Context);
+		c = (MR_Context *) make(MR_Context);
 		c->detstack_zone = NULL;
 		c->nondetstack_zone = NULL;
 #ifdef MR_USE_TRAIL
@@ -137,7 +137,7 @@
 }
 
 void 
-destroy_context(Context *c)
+destroy_context(MR_Context *c)
 {
 	MR_LOCK(free_context_list_lock, "destroy_context");
 	c->next = free_context_list;
Index: mercury_context.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_context.h,v
retrieving revision 1.4
diff -u -u -r1.4 mercury_context.h
--- mercury_context.h	1998/06/09 02:07:51	1.4
+++ mercury_context.h	1998/06/15 06:44:29
@@ -7,9 +7,12 @@
 /*
 ** mercury_context.h - defines Mercury multithreading stuff.
 **
-** A Context is like a thread. It contains a detstack, a nondetstack, a trail,
-** the various pointers that refer to them, a succip, and a thread-
-** resumption continuation. Contexts are initally stored in a free-list.
+** A "context" is a Mercury thread.  (We use a different term than "thread"
+** to avoid confusing Mercury threads and Posix threads.) 
+** Each context is represented by a value of type MR_Context,
+** which contains a detstack, a nondetstack, a trail, the various pointers
+** that refer to them, a succip, and a thread-resumption continuation. 
+** Contexts are initally stored in a free-list.
 ** When one is running, the Posix thread that is executing it has a pointer
 ** to its context structure `this_context'. When a context suspends, it
 ** calls `save_context(context_ptr)' which copies the context from the
@@ -39,7 +42,8 @@
 #ifndef MERCURY_CONTEXT_H
 #define MERCURY_CONTEXT_H
 
-#include "mercury_regs.h"		/* for hp. Must come before system headers. */
+#include "mercury_regs.h"		/* for hp. Must come before
+					   system headers. */
 
 #include <stdio.h>
 
@@ -61,9 +65,9 @@
 ** are prefixed with `context_' so that they don't get replaced
 ** during macro expansion.
 */
-typedef struct CONTEXT Context;
-struct CONTEXT {
-	struct CONTEXT	*next;	
+typedef struct MR_context_struct MR_Context;
+struct MR_context_struct {
+	struct MR_context_struct *next;	
 		/*
 		** if this context is in the free-list `next' will point
 		** to the next free context. If this context is suspended
@@ -122,6 +126,8 @@
 		*/
 };
 
+typedef MR_Context Context;	/* for backwards compatibility */
+
 /*
 ** free_context_list is a global linked list of unused context
 ** structures. If the MemoryZone pointers are not NULL,
@@ -129,15 +135,14 @@
 ** need to be reinitialized, but have space allocated to
 ** them. (see comments in mercury_memory.h about reset_zone())
 */
-extern	Context *free_context_list;
+extern	MR_Context *free_context_list;
 
 /*
 ** the runqueue is a linked list of contexts that are
 ** runnable.
 */
-
-extern		Context		*MR_runqueue;
-extern		Context		*MR_suspended_forks;
+extern		MR_Context	*MR_runqueue;
+extern		MR_Context	*MR_suspended_forks;
 #ifdef	MR_THREAD_SAFE
   extern	MercuryLock	*MR_runqueue_lock;
   extern	MercuryCond	*MR_runqueue_cond;
@@ -147,20 +152,20 @@
 /*
 ** Initializes a context structure.
 */
-void	init_context(Context *context);
+void	init_context(MR_Context *context);
 
 /*
 ** create_context() allocates and initializes a new context
 ** structure.
 */
-Context	*create_context(void);
+MR_Context *create_context(void);
 
 /*
 ** destroy_context(ptr) returns the context structure pointed
 ** to by ptr to the free list, and releases resources as
 ** necessary.
 */
-void	destroy_context(Context *context);
+void	destroy_context(MR_Context *context);
 
 /*
 ** init_thread_stuff() initializes the lock structures for the runqueue.
@@ -179,32 +184,34 @@
 */
 void	flounder(void);
 
-/*
-** schedule(Context *cptr):
-*/
-
 #ifdef	MR_THREAD_SAFE
-  #define schedule(cptr)	do {				\
+  /*
+  ** schedule(MR_Context *cptr):
+  **	Inserts a context onto the start of the run queue.
+  */
+  #define schedule(cptr)					\
+  	do {							\
 		MR_LOCK(MR_runqueue_lock, "schedule");		\
-		((Context *)cptr)->next = MR_runqueue;		\
-		MR_runqueue = (Context *) (cptr);		\
+		((MR_Context *)cptr)->next = MR_runqueue;	\
+		MR_runqueue = (MR_Context *) (cptr);		\
 		MR_SIGNAL(MR_runqueue_cond);			\
 		MR_UNLOCK(MR_runqueue_lock, "schedule");	\
 	} while(0)
 
-	/*
-	** runnext() tries to execute the first context on the
-	** runqueue. If the context was directly called from C
-	** it may only be executed in the thread that the C call
-	** originated in or should the context return to C the
-	** C stack will be wrong!
-	** If there are no contexts that the current thread can
-	** execute, then we suspend until another thread puts something
-	** into the runqueue. Currently, it is not possible for
-	** floundering to occur, so we haven't got a check for it.
-	*/
-  #define runnext()	do {					\
-		Context *rn_c, *rn_p;				\
+  /*
+  ** runnext() tries to execute the first context on the
+  ** runqueue. If the context was directly called from C
+  ** it may only be executed in the thread that the C call
+  ** originated in or should the context return to C the
+  ** C stack will be wrong!
+  ** If there are no contexts that the current thread can
+  ** execute, then we suspend until another thread puts something
+  ** into the runqueue. Currently, it is not possible for
+  ** floundering to occur, so we haven't got a check for it.
+  */
+  #define runnext()						\
+  	do {							\
+		MR_Context *rn_c, *rn_p;			\
 		unsigned x;					\
 		MercuryThread t;				\
 		x = MR_ENGINE(c_depth);				\
@@ -236,12 +243,16 @@
 		GOTO(MR_ENGINE(this_context)->resume);		\
 	} while(0)
 #else
-  #define schedule(cptr)	do {				\
-		((Context *)cptr)->next = MR_runqueue;		\
-		MR_runqueue = (Context *) (cptr);		\
+  /* see above for documentation */
+  #define schedule(cptr)					\
+  	do {							\
+		((MR_Context *)cptr)->next = MR_runqueue;	\
+		MR_runqueue = (MR_Context *) (cptr);		\
 	} while(0)
 
-  #define runnext()	do {					\
+  /* see above for documentation */
+  #define runnext()						\
+  	do {							\
 		if (MR_runqueue == NULL) {			\
 			fatal_error("empty runqueue");		\
 		}						\
@@ -257,6 +268,7 @@
 #else
   #define IF_MR_THREAD_SAFE(x)
 #endif
+
 /*
 ** fork_new_context(Code *child, Code *parent, int numslots):
 ** create a new context to execute the code at `child', and
@@ -265,7 +277,7 @@
 ** context resumes at `parent'.
 */
 #define MR_fork_new_context(child, parent, numslots) do {		\
-		Context	*f_n_c_context;					\
+		MR_Context	*f_n_c_context;				\
 		int	fork_new_context_i;				\
 		f_n_c_context = create_context();			\
 		IF_MR_THREAD_SAFE(					\
@@ -285,40 +297,40 @@
 
 #ifndef	CONSERVATIVE_GC
 
-/*
-** To figure out the maximum amount of heap we can reclaim on backtracking,
-** we compare hp with the context_hp.
-**
-** If context_hp == NULL then this is the first time this context has been
-** scheduled, so the furthest back down the heap we can reclaim is to the
-** current value of hp. 
-**
-** If hp > context_hp, another context has allocated data on the heap since
-** we were last scheduled, so the furthest back that we can reclaim is to
-** the current value of hp, so we set MR_min_hp_rec and the
-** field of the same name in our context structure.
-**
-** If hp < context_hp, then another context has truncated the heap on failure.
-** For this to happen, it must be the case that last time we were scheduled,
-** that other context was the last one to allocate data on the heap, and we
-** did not allocate any heap during that period of execution. That being the
-** case, the furthest back to which we can reset the heap is to the current
-** value of hp. This is a conservative approximation - it is possible that
-** the current value of hp is the same as some previous value that we held,
-** and we are now contiguous with our older data, so this algorithm will lead
-** to holes in the heap, though GC will reclaim these.
-**
-** If hp == context_hp then no other process has allocated any heap since we
-** were last scheduled, so we can proceed as if we had not stopped, and the
-** furthest back that we can backtrack is the same as it was last time we
-** were executing.
-*/
+  /*
+  ** To figure out the maximum amount of heap we can reclaim on backtracking,
+  ** we compare hp with the context_hp.
+  **
+  ** If context_hp == NULL then this is the first time this context has been
+  ** scheduled, so the furthest back down the heap we can reclaim is to the
+  ** current value of hp. 
+  **
+  ** If hp > context_hp, another context has allocated data on the heap since
+  ** we were last scheduled, so the furthest back that we can reclaim is to
+  ** the current value of hp, so we set MR_min_hp_rec and the
+  ** field of the same name in our context structure.
+  **
+  ** If hp < context_hp, then another context has truncated the heap on failure.
+  ** For this to happen, it must be the case that last time we were scheduled,
+  ** that other context was the last one to allocate data on the heap, and we
+  ** did not allocate any heap during that period of execution. That being the
+  ** case, the furthest back to which we can reset the heap is to the current
+  ** value of hp. This is a conservative approximation - it is possible that
+  ** the current value of hp is the same as some previous value that we held,
+  ** and we are now contiguous with our older data, so this algorithm will lead
+  ** to holes in the heap, though GC will reclaim these.
+  **
+  ** If hp == context_hp then no other process has allocated any heap since we
+  ** were last scheduled, so we can proceed as if we had not stopped, and the
+  ** furthest back that we can backtrack is the same as it was last time we
+  ** were executing.
+  */
   #define set_min_heap_reclamation_point(ctxt)	do {		\
 		if (hp != (ctxt)->context_hp 			\
 			|| (ctxt)->context_hp == NULL)		\
 		{						\
-			MR_min_hp_rec = hp;	\
-			(ctxt)->min_hp_rec = hp;\
+			MR_min_hp_rec = hp;			\
+			(ctxt)->min_hp_rec = hp;		\
 		}						\
 		else						\
 		{						\
@@ -326,9 +338,10 @@
 		}						\
 	} while (0)
 
-  #define	save_hp_in_context(ctxt)	do {		\
-		(ctxt)->context_hp = hp;		\
-		(ctxt)->min_hp_rec = MR_min_hp_rec;	\
+  #define save_hp_in_context(ctxt)				\
+  	do {							\
+		(ctxt)->context_hp = hp;			\
+		(ctxt)->min_hp_rec = MR_min_hp_rec;		\
 	} while (0)
 
 #else
@@ -345,13 +358,14 @@
   #define MR_IF_USE_TRAIL(x)
 #endif
 
-#define	load_context(cptr)	do {					\
-		Context	*load_context_c;				\
+#define load_context(cptr)						\
+	do {								\
+		MR_Context	*load_context_c;			\
 		load_context_c = (cptr);				\
-		MR_succip		= load_context_c->context_succip; \
-		MR_sp			= load_context_c->context_sp;	\
-		MR_maxfr		= load_context_c->context_maxfr; \
-		MR_curfr		= load_context_c->context_curfr; \
+		MR_succip	= load_context_c->context_succip;	\
+		MR_sp		= load_context_c->context_sp;		\
+		MR_maxfr	= load_context_c->context_maxfr; 	\
+		MR_curfr	= load_context_c->context_curfr;	\
 	        MR_IF_USE_TRAIL(					\
 		    MR_trail_zone = load_context_c->trail_zone;		\
 		    MR_trail_ptr = load_context_c->context_trail_ptr;	\
@@ -365,8 +379,9 @@
 		set_min_heap_reclamation_point(load_context_c);		\
 	} while (0)
 
-#define	save_context(cptr)	do {					\
-		Context	*save_context_c;				\
+#define save_context(cptr)						\
+	do {								\
+		MR_Context	*save_context_c;			\
 		save_context_c = (cptr);				\
 		save_context_c->context_succip	= MR_succip;		\
 		save_context_c->context_sp	 = MR_sp;		\
@@ -381,20 +396,21 @@
 		save_context_c->detstack_zone =				\
 				MR_ENGINE(context).detstack_zone;	\
 		save_context_c->nondetstack_zone =			\
-				MR_ENGINE(context).nondetstack_zone; \
+				MR_ENGINE(context).nondetstack_zone;	\
 		save_hp_in_context(save_context_c);			\
 	} while (0)
 
-typedef struct SYNCTERM SyncTerm;
-struct SYNCTERM {
+typedef struct sync_term_struct SyncTerm;
+struct sync_term_struct {
   #ifdef MR_THREAD_SAFE
 	MercuryLock	lock;
   #endif
 	int		count;
-	Context		*parent;
+	MR_Context	*parent;
 };
 
-#define MR_init_sync_term(sync_term, nbranches)	do {			\
+#define MR_init_sync_term(sync_term, nbranches)				\
+	do {								\
 		SyncTerm *st = (SyncTerm *) sync_term;			\
 		MR_IF_THREAD_SAFE(					\
 			pthread_mutex_init(&(st->lock), MR_MUTEX_ATTR);	\
@@ -403,7 +419,8 @@
 		st->parent = NULL;					\
 	} while (0)
 
-#define MR_join_and_terminate(sync_term)	do {			\
+#define MR_join_and_terminate(sync_term)				\
+	do {								\
 		SyncTerm *st = (SyncTerm *) sync_term;			\
 		MR_LOCK(&(st->lock), "terminate");			\
 		(st->count)--;						\
@@ -419,7 +436,8 @@
 		runnext();						\
 	} while (0)
 
-#define MR_join_and_continue(sync_term, where_to)	do {		\
+#define MR_join_and_continue(sync_term, where_to)			\
+	do {								\
 		SyncTerm *st = (SyncTerm *) sync_term;			\
 		MR_LOCK(&(st->lock), "continue");			\
 		(st->count)--;						\
@@ -436,4 +454,3 @@
 	} while (0)
 
 #endif /* not MERCURY_CONTEXT_H */
-
Index: mercury_engine.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_engine.c,v
retrieving revision 1.7
diff -u -u -r1.7 mercury_engine.c
--- mercury_engine.c	1998/06/10 06:56:05	1.7
+++ mercury_engine.c	1998/06/15 06:51:11
@@ -47,17 +47,34 @@
 /*
 ** init_engine() calls init_memory() which sets up all the necessary
 ** stuff for allocating memory-zones and other runtime areas (such as
-** the zone structures and context structures). If PARALLEL is defined,
-** this will cause the shared memory to be allocated.
-** Next, init_engine() calls init_processes() which fork()s the right
-** number of processes, and initializes the data structures for coordinating
-** the interaction between multiple processes.
+** the zone structures and context structures).
 */
 void 
 init_engine(MercuryEngine *eng)
 {
+	/*
+	** First, ensure that the truly global stuff has been initialized
+	** (if it was already initialized, this does nothing).
+	*/
+
 	init_memory();
 
+#ifndef USE_GCC_NONLOCAL_GOTOS
+	{
+		static bool made_engine_done_label = FALSE;
+		if (!made_engine_done_label) {
+			make_label("engine_done", LABEL(engine_done),
+				engine_done);
+			made_engine_done_label = TRUE;
+		}
+	}
+#endif
+
+	/*
+	** Second, initialize the per-engine (i.e. normally per Posix thread)
+	** stuff.
+	*/
+
 #ifndef	CONSERVATIVE_GC
 	eng->heap_zone = create_zone("heap", 1, heap_size, next_offset(),
 			heap_zone_size, default_handler);
@@ -67,8 +84,8 @@
 			solutions_heap_size, next_offset(),
 			solutions_heap_zone_size, default_handler);
 	eng->e_sol_hp = eng->solutions_heap_zone->min;
-
 #endif
+
 #ifdef MR_LOWLEVEL_DEBUG
 	/*
 	** Create the dumpstack, used for debugging stack traces.
@@ -76,22 +93,20 @@
 	** the detstack and we never have to worry about the dumpstack
 	** overflowing.
 	*/
-
 	dumpstack_zone = create_zone("dumpstack", 1, detstack_size,
 		next_offset(), detstack_zone_size, default_handler);
 #endif
 
-	eng->this_context = create_context();
-
-#ifndef USE_GCC_NONLOCAL_GOTOS
-	make_label("engine_done", LABEL(engine_done), engine_done);
-#endif
-
 #ifdef	MR_THREAD_SAFE
 	eng->owner_thread = pthread_self();
 	eng->c_depth = 0;
 #endif
 
+	/*
+	** Finally, allocate an initialize context (Mercury thread)
+	** in the engine and initialize the per-context stuff.
+	*/
+	eng->this_context = create_context();
 }
 
 /*---------------------------------------------------------------------------*/
@@ -103,8 +118,7 @@
 
 /*---------------------------------------------------------------------------*/
 
-MercuryEngine
-*create_engine(void)
+MercuryEngine *create_engine(void)
 {
 	MercuryEngine *eng;
 
@@ -113,8 +127,10 @@
 	return eng;
 }
 
-void destroy_engine(MercuryEngine *eng)
+void
+destroy_engine(MercuryEngine *eng)
 {
+	finalize_engine(eng);
 	free(eng);
 }
 
@@ -368,7 +384,7 @@
 {
 	save_registers();
 	debugmsg0("longjmping out...\n");
-	longjmp(*(MR_ENGINE(e_jmp_buf), 1);
+	longjmp(*(MR_ENGINE(e_jmp_buf)), 1);
 }
 
 static Code *
@@ -507,8 +523,9 @@
 #endif
 END_MODULE
 
-/*---------------------------------------------------------------------------*/
 void mercury_sys_init_engine(void); /* suppress gcc warning */
 void mercury_sys_init_engine(void) {
 	special_labels_module();
 }
+
+/*---------------------------------------------------------------------------*/
Index: mercury_engine.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_engine.h,v
retrieving revision 1.4
diff -u -u -r1.4 mercury_engine.h
--- mercury_engine.h	1998/06/09 23:50:28	1.4
+++ mercury_engine.h	1998/06/15 06:50:27
@@ -7,7 +7,7 @@
 /*
 ** mercury_engine.h - definitions for the Mercury runtime engine.
 **
-** For documentation, see the comments in engine.mod.
+** For documentation, see also the comments in mercury_engine.c.
 */
 
 #ifndef	MERCURY_ENGINE_H
@@ -26,7 +26,15 @@
 #include "mercury_types.h"		/* for `Code *' */
 #include "mercury_goto.h"		/* for `Define_entry()' */
 #include "mercury_thread.h"		/* for pthread types */
-#include "mercury_context.h"		/* for MR_IF_USE_TRAIL */
+#include "mercury_context.h"		/* for MR_Context, MR_IF_USE_TRAIL */
+
+/*---------------------------------------------------------------------------*/
+
+/*
+** Global flags that control the behaviour of the Mercury engine(s)
+*/
+
+extern	bool	debugflag[];
 
 #define	PROGFLAG	0
 #define	GOTOFLAG	1
@@ -83,6 +91,13 @@
 
 	} MR_jmp_buf;
 
+/*---------------------------------------------------------------------------*/
+
+/*
+** Replacements for setjmp() and longjmp() that work
+** across calls to Mercury code.
+*/
+
 	/*
 	** MR_setjmp(MR_jmp_buf *env, longjmp_label)
 	**
@@ -105,9 +120,9 @@
 		(setjmp_env)->mercury_env = MR_ENGINE(e_jmp_buf);	\
 		save_regs_to_mem((setjmp_env)->regs);			\
 		(setjmp_env)->saved_succip = MR_succip;			\
-		(setjmp_env)->saved_sp = sp;				\
-		(setjmp_env)->saved_curfr = curfr;			\
-		(setjmp_env)->saved_maxfr = maxfr;			\
+		(setjmp_env)->saved_sp = MR_sp;				\
+		(setjmp_env)->saved_curfr = MR_curfr;			\
+		(setjmp_env)->saved_maxfr = MR_maxfr;			\
 		MR_IF_USE_TRAIL((setjmp_env)->saved_trail_ptr = 	\
 				MR_trail_ptr);				\
 		MR_IF_USE_TRAIL((setjmp_env)->saved_ticket_counter =	\
@@ -116,9 +131,9 @@
 			MR_ENGINE(e_jmp_buf) = (setjmp_env)->mercury_env; \
 			restore_regs_from_mem((setjmp_env)->regs);	\
 			MR_succip = (setjmp_env)->saved_succip;		\
-			sp = (setjmp_env)->saved_sp;			\
-			curfr = (setjmp_env)->saved_curfr;		\
-			maxfr = (setjmp_env)->saved_maxfr;		\
+			MR_sp = (setjmp_env)->saved_sp;			\
+			MR_curfr = (setjmp_env)->saved_curfr;		\
+			MR_maxfr = (setjmp_env)->saved_maxfr;		\
 			MR_IF_USE_TRAIL(MR_trail_ptr = 			\
 					(setjmp_env)->saved_trail_ptr);	\
 			MR_IF_USE_TRAIL(MR_ticket_counter = 		\
@@ -134,9 +149,14 @@
 	*/
 #define MR_longjmp(setjmp_env)	longjmp((setjmp_env)->env, 1)
 
-extern	bool	debugflag[];
+/*---------------------------------------------------------------------------*/
+
+/*
+** The Mercury engine structure.
+**	Normally there is one of these for each Posix thread.
+*/
 
-typedef struct MR_MERCURY_ENGINE {
+typedef struct MR_mercury_engine_struct {
 	Word		fake_reg[MAX_FAKE_REG];
 		/* The fake reg vector for this engine. */
 #ifndef CONSERVATIVE_GC
@@ -145,12 +165,12 @@
 	Word		*e_sol_hp;
 		/* The solutions heap pointer for this engine */
 #endif
-	Context		*this_context;
+	MR_Context	*this_context;
 		/*
 		** this_context points to the context currently
 		** executing in this engine.
 		*/
-	Context		context;
+	MR_Context	context;
 		/*
 		** context stores all the context information
 		** for the context executing in this engine.
@@ -196,8 +216,8 @@
 
   extern MercuryThreadKey	MR_engine_base_key;
 
-  #define MR_thread_engine_base ((MercuryEngine *) \
-  			MR_GETSPECIFIC(MR_engine_base_key))
+  #define MR_thread_engine_base \
+	((MercuryEngine *) MR_GETSPECIFIC(MR_engine_base_key))
 
   #if NUM_REAL_REGS > 0
     #define	MR_ENGINE_BASE_REGISTER
@@ -211,57 +231,59 @@
   #define MR_ENGINE(x)		(((MercuryEngine *)MR_engine_base)->x)
   #define MR_get_engine()	MR_thread_engine_base
 
-  #ifndef	CONSERVATIVE_GC
-  #define IF_NOT_CONSERVATIVE_GC(x)	x
-  #else
-  #define IF_NOT_CONSERVATIVE_GC(x)
-  #endif
-
-  #define load_engine_regs(eng)	do {					\
-		IF_NOT_CONSERVATIVE_GC(MR_hp = (eng)->e_hp;)		\
-		IF_NOT_CONSERVATIVE_GC(MR_sol_hp = (eng)->e_sol_hp;)	\
-	} while (0)
-
-  #define save_engine_regs(eng)	do {					\
-		IF_NOT_CONSERVATIVE_GC((eng)->e_hp = MR_hp;)		\
-		IF_NOT_CONSERVATIVE_GC((eng)->e_sol_hp = MR_sol_hp;)	\
-	} while (0)
-
 #else 	/* !MR_THREAD_SAFE */
 
   extern MercuryEngine	MR_engine_base;
   #define MR_ENGINE(x)		(MR_engine_base.x)
   #define MR_get_engine()	(&MR_engine_base)
 
-  #ifndef	CONSERVATIVE_GC
+
+#endif	/* !MR_THREAD_SAFE */
+
+#ifndef CONSERVATIVE_GC
   #define IF_NOT_CONSERVATIVE_GC(x)	x
-  #else
+#else
   #define IF_NOT_CONSERVATIVE_GC(x)
-  #endif
+#endif
 
-  #define load_engine_regs(eng)	do {					\
+#define load_engine_regs(eng)						\
+  	do {								\
 		IF_NOT_CONSERVATIVE_GC(MR_hp = (eng)->e_hp;)		\
 		IF_NOT_CONSERVATIVE_GC(MR_sol_hp = (eng)->e_sol_hp;)	\
 	} while (0)
 
-  #define save_engine_regs(eng)	do {					\
+#define save_engine_regs(eng)						\
+  	do {								\
 		IF_NOT_CONSERVATIVE_GC((eng)->e_hp = MR_hp;)		\
 		IF_NOT_CONSERVATIVE_GC((eng)->e_sol_hp = MR_sol_hp;)	\
 	} while (0)
 
-
-#endif	/* !MR_THREAD_SAFE */
-
-
+/*
+** Functions for creating/destroying a MercuryEngine.
+*/
 extern	MercuryEngine	*create_engine(void);
 extern	void		destroy_engine(MercuryEngine *engine);
 
+/*
+** Functions for initializing/finalizing a MercuryEngine.
+** These are like create/destroy except that they don't allocate/deallocate
+** the MercuryEngine structure.
+*/
 extern	void	init_engine(MercuryEngine *engine);
 extern	void	finalize_engine(MercuryEngine *engine);
 
+/*
+** Functions that act on the current Mercury engine.
+*/
 extern	void	call_engine(Code *entry_point);
 extern	void	terminate_engine(void);
 extern	void	dump_prev_locations(void);
+
+/*---------------------------------------------------------------------------*/
+
+/*
+** Builtin labels that point to commonly used code fragments
+*/
 
 Declare_entry(do_redo);
 Declare_entry(do_fail);
Index: mercury_regorder.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_regorder.h,v
retrieving revision 1.6
diff -u -u -r1.6 mercury_regorder.h
--- mercury_regorder.h	1998/06/11 02:42:39	1.6
+++ mercury_regorder.h	1998/06/11 21:11:27
@@ -70,15 +70,10 @@
 #define MR_engine_base	LVALUE_CAST(Word *, count_usage(MR_SP_RN, mr0))
 
 #define MR_succip	LVALUE_CAST(Code *, count_usage(MR_SI_RN, mr2))
-#define succip		MR_succip
 #define MR_hp		LVALUE_CAST(Word *, count_usage(MR_HP_RN, mr6))
-#define hp		MR_hp
 #define MR_sp		LVALUE_CAST(Word *, count_usage(MR_SP_RN, mr1))
-#define sp		MR_sp
 #define MR_curfr	LVALUE_CAST(Word *, count_usage(MR_CF_RN, mr9))
-#define curfr		MR_curfr
 #define MR_maxfr	LVALUE_CAST(Word *, count_usage(MR_MF_RN, mr10))
-#define maxfr		MR_maxfr
 #define MR_sol_hp	LVALUE_CAST(Word *, count_usage(MR_SOL_HP_RN, mr(38)))
 #define MR_min_hp_rec	LVALUE_CAST(Word *, count_usage(MR_MIN_HP_REC, mr(39)))
 #define MR_min_sol_hp_rec	LVALUE_CAST(Word *,	\
@@ -197,13 +192,6 @@
 #define MR_ticket_counter	 \
 		count_usage(MR_TICKET_COUNTER_RN, MR_ticket_counter_var)
 
-/* for backwards compatibility */
-#define succip		MR_succip
-#define hp		MR_hp
-#define sp		MR_sp
-#define curfr		MR_curfr
-#define maxfr		MR_maxfr
-
 /* the number of special, non rN registers */
 #define MR_NUM_SPECIAL_REG	10
 
@@ -261,5 +249,12 @@
 }
 
 #endif
+
+/* for backwards compatibility */
+#define succip		MR_succip
+#define hp		MR_hp
+#define sp		MR_sp
+#define curfr		MR_curfr
+#define maxfr		MR_maxfr
 
 #endif /* not MERCURY_REGORDER_H */
Index: mercury_regs.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_regs.h,v
retrieving revision 1.7
diff -u -u -r1.7 mercury_regs.h
--- mercury_regs.h	1998/06/09 02:08:17	1.7
+++ mercury_regs.h	1998/06/11 21:14:19
@@ -136,13 +136,14 @@
 */
 
 #if defined(MR_THREAD_SAFE) && NUM_REAL_REGS > 0
-#define	restore_registers()	do {				\
+  #define restore_registers()					\
+  	do {							\
 		MR_engine_base = MR_thread_engine_base;		\
 		MR_fake_reg[0] = (Word) MR_engine_base;		\
 		restore_regs_from_mem(MR_fake_reg);		\
 	} while (0)
 #else
-#define restore_registers() 	restore_regs_from_mem(MR_fake_reg)
+  #define restore_registers() 	restore_regs_from_mem(MR_fake_reg)
 #endif
 
 /* 
@@ -155,13 +156,14 @@
 
 #define save_transient_registers()    save_transient_regs_to_mem(MR_fake_reg)
 #if defined(MR_THREAD_SAFE) && NUM_REAL_REGS > 0
-#define restore_transient_registers()	do {				\
+  #define restore_transient_registers()					\
+  	do {								\
 		MR_engine_base = MR_thread_engine_base;			\
 		MR_fake_reg[0] = (Word) MR_engine_base;			\
 		restore_transient_regs_from_mem(MR_fake_reg);		\
 	} while (0)
 #else
-#define restore_transient_registers()	\
+  #define restore_transient_registers()	\
 		restore_transient_regs_from_mem(MR_fake_reg)
 #endif
 
@@ -176,7 +178,7 @@
   #define count_usage(num,reg)		(reg)
 #endif
 
-#include	"mercury_regorder.h"
+#include "mercury_regorder.h"
 
 /* mercury_regorder.h defines r1 .. r32; now define r(n) for n > 32 */
 
@@ -186,9 +188,9 @@
 ** saved_reg(save_area, n) accesses the underlying slot in save_area
 ** for register n
 */
-#define saved_reg(save_area, n)	\
-	LVALUE_COND((n) > MAX_REAL_REG, \
-		save_area[(n) + NUM_SPECIAL_REG - 1], \
+#define saved_reg(save_area, n)						\
+	LVALUE_COND((n) > MAX_REAL_REG,					\
+		save_area[(n) + NUM_SPECIAL_REG - 1],			\
 		save_area[virtual_reg_map[(n) - 1]])
 
 /* virtual_reg(n) accesses the underlying fake_reg for register n */
Index: mercury_thread.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_thread.c,v
retrieving revision 1.1
diff -u -u -r1.1 mercury_thread.c
--- mercury_thread.c	1998/06/09 02:28:56	1.1
+++ mercury_thread.c	1998/06/15 06:54:24
@@ -18,7 +18,7 @@
 #include <errno.h>
 
 #ifdef	MR_THREAD_SAFE
-MercuryThreadKey MR_engine_base_key;
+  MercuryThreadKey MR_engine_base_key;
 #endif
 
 bool	MR_exit_now;
@@ -28,7 +28,8 @@
 Declare_entry(do_runnext);
 
 #ifdef MR_THREAD_SAFE
-MercuryThread *create_thread(int x)
+MercuryThread *
+create_thread(int x)
 {
 	MercuryThread *thread;
 	pthread_attr_t attrs;
@@ -48,9 +49,10 @@
 
 	return thread;
 }
-#endif
+#endif /* MR_THREAD_SAFE */
 
-void *init_thread(void *unused)
+void *
+init_thread(void *unused)
 {
 	MercuryEngine *eng;
 
@@ -73,7 +75,7 @@
 		sizeof(MercuryEngine));
 	restore_registers();
 
-	load_engine_regs(MR_engine_base);
+	load_engine_regs(&MR_engine_base);
 	load_context(MR_engine_base.this_context);
 
 	save_registers();
@@ -93,7 +95,8 @@
 }
 
 #ifdef	MR_THREAD_SAFE
-void destroy_thread(void *eng0)
+void
+destroy_thread(void *eng0)
 {
 	MercuryEngine *eng = eng0;
 	destroy_engine(eng);
@@ -102,7 +105,8 @@
 #endif
 
 #ifdef	MR_THREAD_SAFE
-void MR_mutex_lock(MercuryLock *lock, const char *from)
+void
+MR_mutex_lock(MercuryLock *lock, const char *from)
 {
 	int err;
 
@@ -113,33 +117,37 @@
 	assert(err == 0);
 }
 
-void MR_mutex_unlock(MercuryLock *lock, const char *from)
+void
+MR_mutex_unlock(MercuryLock *lock, const char *from)
 {
 	int err;
 
 #if 0
-	fprintf(stderr, "%d unlocking on %p (%s)\n", pthread_self(), lock, from);
+	fprintf(stderr, "%d unlocking on %p (%s)\n",
+		pthread_self(), lock, from);
 #endif
 	err = pthread_mutex_unlock(lock);
 	assert(err == 0);
 }
 
-void MR_cond_signal(MercuryCond *cond)
+void
+MR_cond_signal(MercuryCond *cond)
 {
 	int err;
 
-#ifdef 0
+#if 0
 	fprintf(stderr, "%d signaling %p\n", pthread_self(), cond);
 #endif
 	err = pthread_cond_broadcast(cond);
 	assert(err == 0);
 }
 
-void MR_cond_wait(MercuryCond *cond, MercuryLock *lock)
+void
+MR_cond_wait(MercuryCond *cond, MercuryLock *lock)
 {
 	int err;
 
-#ifdef 0
+#if 0
 	fprintf(stderr, "%d waiting on %p (%p)\n", pthread_self(), cond, lock);
 #endif
 	err = pthread_cond_wait(cond, lock);
Index: mercury_thread.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_thread.h,v
retrieving revision 1.1
diff -u -u -r1.1 mercury_thread.h
--- mercury_thread.h	1998/06/09 02:28:58	1.1
+++ mercury_thread.h	1998/06/11 22:45:40
@@ -17,10 +17,10 @@
     #define MR_THREAD_ATTR	NULL
   #endif
 
-typedef	pthread_t	MercuryThread;
-typedef pthread_key_t	MercuryThreadKey;
-typedef pthread_mutex_t	MercuryLock;
-typedef pthread_cond_t	MercuryCond;
+  typedef pthread_t		MercuryThread;
+  typedef pthread_key_t		MercuryThreadKey;
+  typedef pthread_mutex_t	MercuryLock;
+  typedef pthread_cond_t	MercuryCond;
 
   #if 0
 	/*
@@ -59,9 +59,9 @@
     #define	MR_KEY_CREATE		pthread_key_create
   #endif
 
-MercuryThread	*create_thread(int x);
-void		destroy_thread(void *eng);
-extern bool	MR_exit_now;
+  MercuryThread	*create_thread(int x);
+  void		destroy_thread(void *eng);
+  extern bool	MR_exit_now;
 
 #else /* not MR_THREAD_SAFE */
 
Index: mercury_type_info.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_type_info.c,v
retrieving revision 1.7
diff -u -u -r1.7 mercury_type_info.c
--- mercury_type_info.c	1998/06/02 05:34:42	1.7
+++ mercury_type_info.c	1998/06/15 06:28:11
@@ -545,11 +545,11 @@
 enum MR_DataRepresentation
 MR_categorize_data(Word functors_indicator, Word layout_entry)
 {
-	switch (functors_indicator) { 
+	switch ((int) functors_indicator) { 
 		case MR_TYPEFUNCTORS_ENUM: 
 			return MR_DATAREP_ENUM;
 		case MR_TYPEFUNCTORS_DU: 
-			switch (tag(layout_entry)) {
+			switch ((int) tag(layout_entry)) {
 				case TYPELAYOUT_SIMPLE_TAG:
 					return MR_DATAREP_SIMPLE;
 				case TYPELAYOUT_COMPLICATED_TAG:
cvs diff: Diffing machdeps
-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3        |     -- the last words of T. S. Garp.



More information about the developers mailing list