[m-rev.] for review: --debug-threads runtime option

Peter Ross pro at missioncriticalit.com
Mon Mar 3 23:48:06 AEDT 2003


Hi,

For fjh to review.


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


Estimated hours taken: 1
Branches: main, release

Allow one to turn thread debugging on at runtime.
However only modules which are compiled with MR_DEBUG_THREADS will
have debugging messages output.

runtime/mercury_thread.c:
	Add MR_debug_threads global variable which is used to control
	whether debugging messages are output.
	Always include the debug version of lock, unlock, signal and
	wait in the runtime library.

runtime/mercury_thread.h:
	When MR_DEBUG_THREADS is defined, conditionally choose using
	the MR_debug_threads global variable between the debug and the
	pthread library versions of lock, unlock, signal and wait.
	
runtime/mercury_wrapper.c:
	Parse the --debug-threads option in the MERCURY_OPTIONS
	environment variable.

doc/user_guide.texi:
	Document --debug-threads.

Index: runtime/mercury_thread.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_thread.c,v
retrieving revision 1.19.2.1
diff -u -r1.19.2.1 mercury_thread.c
--- runtime/mercury_thread.c	2 Mar 2003 11:43:13 -0000	1.19.2.1
+++ runtime/mercury_thread.c	3 Mar 2003 12:36:17 -0000
@@ -21,6 +21,7 @@
 #endif
 
 MR_bool	MR_exit_now;
+MR_bool MR_debug_threads = MR_FALSE;
 
 #ifdef MR_THREAD_SAFE
 
@@ -156,7 +157,7 @@
 
 #endif
 
-#if defined(MR_THREAD_SAFE) && defined(MR_DEBUG_THREADS)
+#if defined(MR_THREAD_SAFE)
 
 void
 MR_mutex_lock(MercuryLock *lock, const char *from)
Index: runtime/mercury_thread.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_thread.h,v
retrieving revision 1.11.2.1
diff -u -r1.11.2.1 mercury_thread.h
--- runtime/mercury_thread.h	2 Mar 2003 11:43:13 -0000	1.11.2.1
+++ runtime/mercury_thread.h	3 Mar 2003 12:36:17 -0000
@@ -41,16 +41,24 @@
     #define	MR_SIGNAL(cnd)		pthread_cond_signal((cnd))
     #define	MR_WAIT(cnd, mtx)	pthread_cond_wait((cnd), (mtx))
   #else
-    void MR_mutex_lock(MercuryLock *lock, const char *from);
-    void MR_mutex_unlock(MercuryLock *lock, const char *from);
-    void MR_cond_signal(MercuryCond *cond);
-    void MR_cond_wait(MercuryCond *cond, MercuryLock *lock);
+    #define	MR_LOCK(lck, from)					\
+    				( MR_debug_threads ?			\
+					MR_mutex_lock((lck), (from))	\
+				:	pthread_mutex_lock((lck)))
+    #define	MR_UNLOCK(lck, from)					\
+    				( MR_debug_threads ?			\
+    					MR_mutex_unlock((lck), (from))	\
+				:	pthread_mutex_unlock((lck)))
+
+    #define	MR_SIGNAL(cnd)						\
+    				( MR_debug_threads ?			\
+					MR_cond_signal((cnd))		\
+				:	pthread_cond_signal((cnd)))
+    #define	MR_WAIT(cnd, mtx)					\
+    				( MR_debug_threads ?			\
+					MR_cond_wait((cnd), (mtx))	\
+				:	pthread_cond_wait((cnd), (mtx)))
 
-    #define	MR_LOCK(lck, from)	MR_mutex_lock((lck), (from))
-    #define	MR_UNLOCK(lck, from)	MR_mutex_unlock((lck), (from))
-
-    #define	MR_SIGNAL(cnd)		MR_cond_signal((cnd))
-    #define	MR_WAIT(cnd, mtx)	MR_cond_wait((cnd), (mtx))
   #endif
 
     	/*
@@ -109,6 +117,12 @@
 	*/
   extern MercuryThreadKey MR_exception_handler_key;
 
+  	/*
+	** Variable used to determine whether to print debug messages
+	** for threads.
+	*/
+  extern MR_bool	MR_debug_threads;
+
 #else /* not MR_THREAD_SAFE */
 
   #define MR_LOCK(nothing, from)	do { } while (0)
@@ -158,5 +172,10 @@
 */
 
 extern	void    MR_finalize_thread_engine(void);
+
+void MR_mutex_lock(MercuryLock *lock, const char *from);
+void MR_mutex_unlock(MercuryLock *lock, const char *from);
+void MR_cond_signal(MercuryCond *cond);
+void MR_cond_wait(MercuryCond *cond, MercuryLock *lock);
 
 #endif
Index: runtime/mercury_wrapper.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_wrapper.c,v
retrieving revision 1.114
diff -u -r1.114 mercury_wrapper.c
--- runtime/mercury_wrapper.c	8 Nov 2002 00:45:48 -0000	1.114
+++ runtime/mercury_wrapper.c	3 Mar 2003 12:36:17 -0000
@@ -842,7 +842,8 @@
 	MR_MDB_ERR,
 	MR_MDB_IN_WINDOW,
 	MR_FORCE_READLINE,
-	MR_NUM_OUTPUT_ARGS
+	MR_NUM_OUTPUT_ARGS,
+	MR_DEBUG_THREADS_OPT
 };
 
 struct MR_option MR_long_opts[] = {
@@ -863,7 +864,8 @@
 	{ "mdb-err", 			1, 0, MR_MDB_ERR },
 	{ "mdb-in-window",		0, 0, MR_MDB_IN_WINDOW },
 	{ "force-readline",		0, 0, MR_FORCE_READLINE },
-	{ "num-output-args", 		1, 0, MR_NUM_OUTPUT_ARGS }
+	{ "num-output-args", 		1, 0, MR_NUM_OUTPUT_ARGS },
+	{ "debug-threads",		0, 0, MR_DEBUG_THREADS_OPT }
 };
 
 static void
@@ -1001,6 +1003,10 @@
 			fflush(stdout);
 			exit(1);
 #endif
+			break;
+
+		case MR_DEBUG_THREADS_OPT:
+			MR_debug_threads = MR_TRUE;
 			break;
 
 		case 'a':
Index: doc/user_guide.texi
===================================================================
RCS file: /home/mercury1/repository/mercury/doc/user_guide.texi,v
retrieving revision 1.342.2.4
diff -u -r1.342.2.4 user_guide.texi
--- doc/user_guide.texi	1 Mar 2003 08:16:16 -0000	1.342.2.4
+++ doc/user_guide.texi	3 Mar 2003 12:36:18 -0000
@@ -6754,6 +6754,13 @@
 @c --mdb-in-window is for use only by the mdb script, so it's
 @c not documented here.
 
+ at sp 1
+ at itemx --debug-threads
+ at findex --debug-threads (runtime option)
+
+Output information to stderr about the locking and unlocking occuring in each
+module which has been compiled with MR_DEBUG_THREADS defined.
+
 @end table
 
 @sp 1

--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list