[m-rev.] diff: rename macros for condition variables

Julien Fischer jfischer at opturion.com
Wed Oct 5 13:12:25 AEDT 2016


As suggested by Peter the other day.

--------------------

Rename the macros for condition variables.

runtime/mercury_thread.h:
    Rename MR_WAIT to MR_COND_WAIT etc.

runtime/mercury_wrapper.c:
library/thread.m:
library/thread.semaphore.m:
     Conform to the above change.

Julien.

diff --git a/library/thread.m b/library/thread.m
index c54e5c8..0d80e9b 100644
--- a/library/thread.m
+++ b/library/thread.m
@@ -654,7 +654,7 @@ call_back_to_mercury(Goal, ThreadId, !IO) :-
      MR_thread_barrier_count--;
    #ifdef MR_HIGHLEVEL_CODE
      if (MR_thread_barrier_count == 0) {
-        MR_SIGNAL(&MR_thread_barrier_cond, ""ML_decr_thread_barrier_count"");
+        MR_COND_SIGNAL(&MR_thread_barrier_cond, ""ML_decr_thread_barrier_count"");
      }
    #else
      if (MR_thread_barrier_count == 0) {
diff --git a/library/thread.semaphore.m b/library/thread.semaphore.m
index 37d9e19..86384be 100644
--- a/library/thread.semaphore.m
+++ b/library/thread.semaphore.m
@@ -254,7 +254,7 @@ ML_finalize_semaphore(void *obj, void *cd)

      sem = (ML_Semaphore *) Semaphore;

-    MR_LOCK(&(sem->lock), ""semaphore__signal"");
+    MR_LOCK(&(sem->lock), ""semaphore.signal"");

  #ifndef MR_HIGHLEVEL_CODE
      if (sem->count >= 0 && sem->suspended_head != NULL) {
@@ -265,7 +265,7 @@ ML_finalize_semaphore(void *obj, void *cd)
              sem->suspended_tail = ctxt->MR_ctxt_next;
              assert(sem->suspended_tail == NULL);
          }
-        MR_UNLOCK(&(sem->lock), ""semaphore__signal"");
+        MR_UNLOCK(&(sem->lock), ""semaphore.signal"");
          MR_schedule_context(ctxt);

          /* yield() */
@@ -288,7 +288,7 @@ ML_finalize_semaphore(void *obj, void *cd)
        #endif
      } else {
          sem->count++;
-        MR_UNLOCK(&(sem->lock), ""semaphore__signal"");
+        MR_UNLOCK(&(sem->lock), ""semaphore.signal"");

          /* yield() */
          MR_save_context(MR_ENGINE(MR_eng_this_context));
@@ -310,8 +310,8 @@ ML_finalize_semaphore(void *obj, void *cd)
      }
  #else
      sem->count++;
-    MR_SIGNAL(&(sem->cond), ""semaphore.signal"");
-    MR_UNLOCK(&(sem->lock), ""semaphore__signal"");
+    MR_COND_SIGNAL(&(sem->cond), ""semaphore.signal"");
+    MR_UNLOCK(&(sem->lock), ""semaphore.signal"");
  #endif
  ").

@@ -353,12 +353,12 @@ ML_finalize_semaphore(void *obj, void *cd)

      sem = (ML_Semaphore *) Semaphore;

-    MR_LOCK(&(sem->lock), ""semaphore__wait"");
+    MR_LOCK(&(sem->lock), ""semaphore.wait"");

  #ifndef MR_HIGHLEVEL_CODE
      if (sem->count > 0) {
          sem->count--;
-        MR_UNLOCK(&(sem->lock), ""semaphore__wait"");
+        MR_UNLOCK(&(sem->lock), ""semaphore.wait"");
      } else {
          MR_save_context(MR_ENGINE(MR_eng_this_context));

@@ -377,7 +377,7 @@ ML_finalize_semaphore(void *obj, void *cd)
              sem->suspended_head = ctxt;
              sem->suspended_tail = ctxt;
          }
-        MR_UNLOCK(&(sem->lock), ""semaphore__wait"");
+        MR_UNLOCK(&(sem->lock), ""semaphore.wait"");

          /* Make the current engine do something else. */
          MR_ENGINE(MR_eng_this_context) = NULL;
@@ -394,14 +394,14 @@ ML_finalize_semaphore(void *obj, void *cd)
          ** return prematurely with the error code EINTR in glibc 2.3.2
          ** if the thread is sent a signal.
          */
-        while (MR_WAIT(&(sem->cond), &(sem->lock), ""semaphore.wait"") != 0) {
+        while (MR_COND_WAIT(&(sem->cond), &(sem->lock), ""semaphore.wait"") != 0) {
              /* do nothing */
          }
      }

      sem->count--;

-    MR_UNLOCK(&(sem->lock), ""semaphore__wait"");
+    MR_UNLOCK(&(sem->lock), ""semaphore.wait"");
  #endif
  ").

diff --git a/runtime/mercury_thread.h b/runtime/mercury_thread.h
index 459f06a..32de40d 100644
--- a/runtime/mercury_thread.h
+++ b/runtime/mercury_thread.h
@@ -77,10 +77,10 @@
      #define MR_LOCK(lck, from)      pthread_mutex_lock((lck))
      #define MR_UNLOCK(lck, from)    pthread_mutex_unlock((lck))

-    #define MR_SIGNAL(cnd, from)    pthread_cond_signal((cnd))
-    #define MR_BROADCAST(cnd, from) pthread_cond_broadcast((cnd))
-    #define MR_WAIT(cnd, mtx, from) pthread_cond_wait((cnd), (mtx))
-    #define MR_TIMED_WAIT(cond, mtx, abstime, from)                     \
+    #define MR_COND_SIGNAL(cnd, from)    pthread_cond_signal((cnd))
+    #define MR_COND_BROADCAST(cnd, from) pthread_cond_broadcast((cnd))
+    #define MR_COND_WAIT(cnd, mtx, from) pthread_cond_wait((cnd), (mtx))
+    #define MR_COND_TIMED_WAIT(cond, mtx, abstime, from)                     \
          pthread_cond_timedwait((cond), (mtx), (abstime))

      #if defined(MR_USE_LIBDISPATCH)
@@ -111,25 +111,25 @@
                      pthread_mutex_unlock((lck))                         \
                  )

-    #define MR_SIGNAL(cnd, from)                                        \
+    #define MR_COND_SIGNAL(cnd, from)                                   \
                  ( MR_debug_threads ?                                    \
                      MR_cond_signal((cnd), (from))                       \
                  :                                                       \
                      pthread_cond_signal((cnd))                          \
                  )
-    #define MR_BROADCAST(cnd, from)                                     \
+    #define MR_COND_BROADCAST(cnd, from)                                \
                  ( MR_debug_threads ?                                    \
                      MR_cond_broadcast((cnd), (from))                    \
                  :                                                       \
                      pthread_cond_broadcast((cnd))                       \
                  )
-    #define MR_WAIT(cnd, mtx, from)                                     \
+    #define MR_COND_WAIT(cnd, mtx, from)                                \
                  ( MR_debug_threads ?                                    \
                      MR_cond_wait((cnd), (mtx), (from))                  \
                  :                                                       \
                      pthread_cond_wait((cnd), (mtx))                     \
                  )
-    #define MR_TIMED_WAIT(cond, mtx, abstime, from)                     \
+    #define MR_COND_TIMED_WAIT(cond, mtx, abstime, from)                \
          ( MR_debug_threads ?                                            \
              MR_cond_timed_wait((cond), (mtx), (abstime), (from))        \
          :                                                               \
@@ -238,9 +238,9 @@
    #define MR_LOCK(nothing, from)        do { } while (0)
    #define MR_UNLOCK(nothing, from)      do { } while (0)

-  #define MR_SIGNAL(nothing, from)      do { } while (0)
-  #define MR_BROADCAST(nothing, from)   do { } while (0)
-  #define MR_WAIT(no, thing, from)      (0)
+  #define MR_COND_SIGNAL(nothing, from)    do { } while (0)
+  #define MR_COND_BROADCAST(nothing, from) do { } while (0)
+  #define MR_COND_WAIT(no, thing, from)    (0)

    #define MR_OBTAIN_GLOBAL_LOCK(where)  do { } while (0)
    #define MR_RELEASE_GLOBAL_LOCK(where) do { } while (0)
diff --git a/runtime/mercury_wrapper.c b/runtime/mercury_wrapper.c
index 5d50463..25c0284 100644
--- a/runtime/mercury_wrapper.c
+++ b/runtime/mercury_wrapper.c
@@ -2755,7 +2755,7 @@ MR_do_interpreter(void)
      assert(MR_thread_equal(pthread_self(), MR_primordial_thread));
      MR_LOCK(&MR_thread_barrier_lock, "MR_do_interpreter");
      while (MR_thread_barrier_count > 0) {
-        while (MR_WAIT(&MR_thread_barrier_cond, &MR_thread_barrier_lock,
+        while (MR_COND_WAIT(&MR_thread_barrier_cond, &MR_thread_barrier_lock,
                  "MR_do_interpreter") != 0)
              ;
      }
r


More information about the reviews mailing list