From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2155) id ED43639DC4E2; Thu, 29 Jul 2021 15:45:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org ED43639DC4E2 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Corinna Vinschen To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin] Cygwin: implement pthread_cond_clockwait X-Act-Checkin: newlib-cygwin X-Git-Author: Corinna Vinschen X-Git-Refname: refs/heads/master X-Git-Oldrev: edf48054e936055c86ef81ee99f6affb20e90d7c X-Git-Newrev: 123454f9d0bd72b34d9fb91dd9f91e1c38597d3c Message-Id: <20210729154549.ED43639DC4E2@sourceware.org> Date: Thu, 29 Jul 2021 15:45:49 +0000 (GMT) X-BeenThere: cygwin-cvs@cygwin.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Cygwin core component git logs List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 29 Jul 2021 15:45:50 -0000 https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=123454f9d0bd72b34d9fb91dd9f91e1c38597d3c commit 123454f9d0bd72b34d9fb91dd9f91e1c38597d3c Author: Corinna Vinschen Date: Thu Jul 29 17:21:01 2021 +0200 Cygwin: implement pthread_cond_clockwait Signed-off-by: Corinna Vinschen 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) {