[m-rev.] for review: fix thread debugging
Ben Mellor
bmellor at csse.unimelb.edu.au
Sun May 3 22:26:49 AEST 2009
Update the debugging thread synchronization procedures to match the pthread_*
calls that are made when thread debugging is not enabled.
runtime/mercury_thread.c
runtime/mercury_thread.h
Update the functions to which the debug versions of MR_LOCK,
MR_UNLOCK, MR_SIGNAL, etc, expand. Make them all return int error
codes, as do the underlying pthread_* functions, make
MR_cond_signal call pthread_cond_signal instead of
pthread_cond_broadcast, and create an analogous MR_cond_broadcast
function.
Index: runtime/mercury_thread.c
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/runtime/mercury_thread.c,v
retrieving revision 1.33
diff -u -r1.33 mercury_thread.c
--- runtime/mercury_thread.c 1 May 2007 01:11:42 -0000 1.33
+++ runtime/mercury_thread.c 3 May 2009 07:16:32 -0000
@@ -195,7 +195,7 @@
#if defined(MR_THREAD_SAFE)
-void
+int
MR_mutex_lock(MercuryLock *lock, const char *from)
{
int err;
@@ -204,9 +204,10 @@
(long) pthread_self(), lock, from);
err = pthread_mutex_lock(lock);
assert(err == 0);
+ return err;
}
-void
+int
MR_mutex_unlock(MercuryLock *lock, const char *from)
{
int err;
@@ -215,19 +216,32 @@
(long) pthread_self(), lock, from);
err = pthread_mutex_unlock(lock);
assert(err == 0);
+ return err;
}
-void
+int
MR_cond_signal(MercuryCond *cond)
{
int err;
fprintf(stderr, "%ld signaling %p\n", (long) pthread_self(), cond);
+ err = pthread_cond_signal(cond);
+ assert(err == 0);
+ return err;
+}
+
+int
+MR_cond_broadcast(MercuryCond *cond)
+{
+ int err;
+
+ fprintf(stderr, "%ld signaling %p\n", (long) pthread_self(), cond);
err = pthread_cond_broadcast(cond);
assert(err == 0);
+ return err;
}
-void
+int
MR_cond_wait(MercuryCond *cond, MercuryLock *lock)
{
int err;
@@ -236,6 +250,7 @@
cond, lock);
err = pthread_cond_wait(cond, lock);
assert(err == 0);
+ return err;
}
#endif /* MR_THREAD_SAFE */
Index: runtime/mercury_thread.h
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/runtime/mercury_thread.h,v
retrieving revision 1.25
diff -u -r1.25 mercury_thread.h
--- runtime/mercury_thread.h 19 Mar 2008 05:30:00 -0000 1.25
+++ runtime/mercury_thread.h 3 May 2009 07:16:32 -0000
@@ -31,10 +31,11 @@
typedef pthread_mutex_t MercuryLock;
typedef pthread_cond_t MercuryCond;
- 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);
+ int MR_mutex_lock(MercuryLock *lock, const char *from);
+ int MR_mutex_unlock(MercuryLock *lock, const char *from);
+ int MR_cond_signal(MercuryCond *cond);
+ int MR_cond_broadcast(MercuryCond *cond);
+ int MR_cond_wait(MercuryCond *cond, MercuryLock *lock);
extern MR_bool MR_debug_threads;
--------------------------------------------------------------------------
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