[newlib-cygwin] Cygwin: implement pthread_cond_clockwait

Corinna Vinschen corinna@sourceware.org
Thu Jul 29 15:45:49 GMT 2021


https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=123454f9d0bd72b34d9fb91dd9f91e1c38597d3c

commit 123454f9d0bd72b34d9fb91dd9f91e1c38597d3c
Author: Corinna Vinschen <corinna@vinschen.de>
Date:   Thu Jul 29 17:21:01 2021 +0200

    Cygwin: implement pthread_cond_clockwait
    
    Signed-off-by: Corinna Vinschen <corinna@vinschen.de>

Diff:
---
 winsup/cygwin/common.din        |  1 +
 winsup/cygwin/include/pthread.h |  4 +++
 winsup/cygwin/thread.cc         | 54 ++++++++++++++++++++++++++++++++---------
 3 files changed, 48 insertions(+), 11 deletions(-)

diff --git a/winsup/cygwin/common.din b/winsup/cygwin/common.din
index ce6ed78c8..a664f1d09 100644
--- a/winsup/cygwin/common.din
+++ b/winsup/cygwin/common.din
@@ -1092,6 +1092,7 @@ pthread_barrierattr_init SIGFE
 pthread_barrierattr_setpshared SIGFE
 pthread_cancel SIGFE
 pthread_cond_broadcast SIGFE
+pthread_cond_clockwait SIGFE
 pthread_cond_destroy SIGFE
 pthread_cond_init SIGFE
 pthread_cond_signal SIGFE
diff --git a/winsup/cygwin/include/pthread.h b/winsup/cygwin/include/pthread.h
index 327926ced..e82a111ce 100644
--- a/winsup/cygwin/include/pthread.h
+++ b/winsup/cygwin/include/pthread.h
@@ -120,6 +120,10 @@ int pthread_cond_broadcast (pthread_cond_t *);
 int pthread_cond_destroy (pthread_cond_t *);
 int pthread_cond_init (pthread_cond_t *, const pthread_condattr_t *);
 int pthread_cond_signal (pthread_cond_t *);
+#if __GNU_VISIBLE
+int pthread_cond_clockwait (pthread_cond_t *, pthread_mutex_t *,
+			    clockid_t, const struct timespec *);
+#endif
 int pthread_cond_timedwait (pthread_cond_t *,
 			    pthread_mutex_t *, const struct timespec *);
 int pthread_cond_wait (pthread_cond_t *, pthread_mutex_t *);
diff --git a/winsup/cygwin/thread.cc b/winsup/cygwin/thread.cc
index 36b78b309..97fcf0c05 100644
--- a/winsup/cygwin/thread.cc
+++ b/winsup/cygwin/thread.cc
@@ -2965,13 +2965,31 @@ __pthread_cond_wait_init (pthread_cond_t *cond, pthread_mutex_t *mutex)
   return 0;
 }
 
-extern "C" int
-pthread_cond_timedwait (pthread_cond_t *cond, pthread_mutex_t *mutex,
-			const struct timespec *abstime)
+static int
+__pthread_cond_clockwait (pthread_cond_t *cond, pthread_mutex_t *mutex,
+			  clockid_t clock_id, const struct timespec *abstime)
 {
   int err = 0;
   LARGE_INTEGER timeout;
 
+  do
+    {
+      err = pthread_convert_abstime (clock_id, abstime, &timeout);
+      if (err)
+	break;
+
+      err = (*cond)->wait (*mutex, &timeout);
+    }
+  while (err == ETIMEDOUT);
+  return err;
+}
+
+extern "C" int
+pthread_cond_clockwait (pthread_cond_t *cond, pthread_mutex_t *mutex,
+			clockid_t clock_id, const struct timespec *abstime)
+{
+  int err = 0;
+
   pthread_testcancel ();
 
   __try
@@ -2979,16 +2997,30 @@ pthread_cond_timedwait (pthread_cond_t *cond, pthread_mutex_t *mutex,
       err = __pthread_cond_wait_init (cond, mutex);
       if (err)
 	__leave;
+      err = __pthread_cond_clockwait (cond, mutex, clock_id, abstime);
+    }
+  __except (NO_ERROR)
+    {
+      return EINVAL;
+    }
+  __endtry
+  return err;
+}
 
-      do
-	{
-	  err = pthread_convert_abstime ((*cond)->clock_id, abstime, &timeout);
-	  if (err)
-	    __leave;
+extern "C" int
+pthread_cond_timedwait (pthread_cond_t *cond, pthread_mutex_t *mutex,
+			const struct timespec *abstime)
+{
+  int err = 0;
 
-	  err = (*cond)->wait (*mutex, &timeout);
-	}
-      while (err == ETIMEDOUT);
+  pthread_testcancel ();
+
+  __try
+    {
+      err = __pthread_cond_wait_init (cond, mutex);
+      if (err)
+	__leave;
+      err = __pthread_cond_clockwait (cond, mutex, (*cond)->clock_id, abstime);
     }
   __except (NO_ERROR)
     {


More information about the Cygwin-cvs mailing list