public inbox for cygwin-cvs@sourceware.org help / color / mirror / Atom feed
From: Corinna Vinschen <corinna@sourceware.org> To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin] Cygwin: implement pthread_cond_clockwait Date: Thu, 29 Jul 2021 15:45:49 +0000 (GMT) [thread overview] Message-ID: <20210729154549.ED43639DC4E2@sourceware.org> (raw) 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) {
reply other threads:[~2021-07-29 15:45 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20210729154549.ED43639DC4E2@sourceware.org \ --to=corinna@sourceware.org \ --cc=cygwin-cvs@sourceware.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).