From: Corinna Vinschen Date: Thu, 3 Aug 2017 19:31:38 +0000 (+0200) Subject: cygwin: Implement pthread_rwlock_timedrdlock, pthread_rwlock_timedwrlock X-Git-Tag: newlib-snapshot-20170818~15 X-Git-Url: https://sourceware.org/git/?a=commitdiff_plain;h=8128f5482f2b1889e2336488e9d45a33c9972d11;p=newlib-cygwin.git cygwin: Implement pthread_rwlock_timedrdlock, pthread_rwlock_timedwrlock Signed-off-by: Corinna Vinschen --- diff --git a/winsup/cygwin/common.din b/winsup/cygwin/common.din index 9c8da379d..8da432b8a 100644 --- a/winsup/cygwin/common.din +++ b/winsup/cygwin/common.din @@ -1085,6 +1085,8 @@ pthread_once SIGFE pthread_rwlock_destroy SIGFE pthread_rwlock_init SIGFE pthread_rwlock_rdlock SIGFE +pthread_rwlock_timedrdlock SIGFE +pthread_rwlock_timedwrlock SIGFE pthread_rwlock_tryrdlock SIGFE pthread_rwlock_trywrlock SIGFE pthread_rwlock_unlock SIGFE diff --git a/winsup/cygwin/include/cygwin/version.h b/winsup/cygwin/include/cygwin/version.h index a84242132..efd4ac017 100644 --- a/winsup/cygwin/include/cygwin/version.h +++ b/winsup/cygwin/include/cygwin/version.h @@ -480,12 +480,13 @@ details. */ 313: Export fls, flsl, flsll. 314: Export explicit_bzero. 315: Export pthread_mutex_timedlock. + 316: Export pthread_rwlock_timedrdlock, pthread_rwlock_timedwrlock. Note that we forgot to bump the api for ualarm, strtoll, strtoull, sigaltstack, sethostname. */ #define CYGWIN_VERSION_API_MAJOR 0 -#define CYGWIN_VERSION_API_MINOR 315 +#define CYGWIN_VERSION_API_MINOR 316 /* There is also a compatibity version number associated with the shared memory regions. It is incremented when incompatible changes are made to the shared diff --git a/winsup/cygwin/release/2.9.0 b/winsup/cygwin/release/2.9.0 index 0fb4a070b..421d6f24f 100644 --- a/winsup/cygwin/release/2.9.0 +++ b/winsup/cygwin/release/2.9.0 @@ -1,7 +1,10 @@ What's new: ----------- -- New APIs: explicit_bzero, pthread_mutex_timedwait. +- New APIs: explicit_bzero. + +- New APIs: pthread_mutex_timedwait, pthread_rwlock_timedrdlock, + pthread_rwlock_timedwrlock. What changed: diff --git a/winsup/cygwin/thread.cc b/winsup/cygwin/thread.cc index c06c077c8..963c4017b 100644 --- a/winsup/cygwin/thread.cc +++ b/winsup/cygwin/thread.cc @@ -1413,7 +1413,7 @@ pthread_rwlock::~pthread_rwlock () } int -pthread_rwlock::rdlock () +pthread_rwlock::rdlock (PLARGE_INTEGER timeout) { int result = 0; struct RWLOCK_READER *reader; @@ -1435,7 +1435,7 @@ pthread_rwlock::rdlock () pthread_cleanup_push (pthread_rwlock::rdlock_cleanup, this); ++waiting_readers; - cond_readers.wait (&mtx); + cond_readers.wait (&mtx, timeout); --waiting_readers; pthread_cleanup_pop (0); @@ -1481,7 +1481,7 @@ pthread_rwlock::tryrdlock () } int -pthread_rwlock::wrlock () +pthread_rwlock::wrlock (PLARGE_INTEGER timeout) { int result = 0; pthread_t self = pthread::self (); @@ -1499,7 +1499,7 @@ pthread_rwlock::wrlock () pthread_cleanup_push (pthread_rwlock::wrlock_cleanup, this); ++waiting_writers; - cond_writers.wait (&mtx); + cond_writers.wait (&mtx, timeout); --waiting_writers; pthread_cleanup_pop (0); @@ -3045,6 +3045,37 @@ pthread_rwlock_rdlock (pthread_rwlock_t *rwlock) return (*rwlock)->rdlock (); } +extern "C" int +pthread_rwlock_timedrdlock (pthread_rwlock_t *rwlock, + const struct timespec *abstime) +{ + LARGE_INTEGER timeout; + + pthread_testcancel (); + + if (pthread_rwlock::is_initializer (rwlock)) + pthread_rwlock::init (rwlock, NULL); + if (!pthread_rwlock::is_good_object (rwlock)) + return EINVAL; + + /* According to SUSv3, abstime need not be checked for validity, + if the rwlock can be locked immediately. */ + if (!(*rwlock)->tryrdlock ()) + return 0; + + __try + { + int err = pthread_convert_abstime (CLOCK_REALTIME, abstime, &timeout); + if (err) + return err; + + return (*rwlock)->rdlock (&timeout); + } + __except (NO_ERROR) {} + __endtry + return EINVAL; +} + extern "C" int pthread_rwlock_tryrdlock (pthread_rwlock_t *rwlock) { @@ -3069,6 +3100,37 @@ pthread_rwlock_wrlock (pthread_rwlock_t *rwlock) return (*rwlock)->wrlock (); } +extern "C" int +pthread_rwlock_timedwrlock (pthread_rwlock_t *rwlock, + const struct timespec *abstime) +{ + LARGE_INTEGER timeout; + + pthread_testcancel (); + + if (pthread_rwlock::is_initializer (rwlock)) + pthread_rwlock::init (rwlock, NULL); + if (!pthread_rwlock::is_good_object (rwlock)) + return EINVAL; + + /* According to SUSv3, abstime need not be checked for validity, + if the rwlock can be locked immediately. */ + if (!(*rwlock)->trywrlock ()) + return 0; + + __try + { + int err = pthread_convert_abstime (CLOCK_REALTIME, abstime, &timeout); + if (err) + return err; + + return (*rwlock)->wrlock (&timeout); + } + __except (NO_ERROR) {} + __endtry + return EINVAL; +} + extern "C" int pthread_rwlock_trywrlock (pthread_rwlock_t *rwlock) { diff --git a/winsup/cygwin/thread.h b/winsup/cygwin/thread.h index 88586ac4e..12a9ef26d 100644 --- a/winsup/cygwin/thread.h +++ b/winsup/cygwin/thread.h @@ -587,10 +587,10 @@ public: } *readers; fast_mutex readers_mx; - int rdlock (); + int rdlock (PLARGE_INTEGER timeout = NULL); int tryrdlock (); - int wrlock (); + int wrlock (PLARGE_INTEGER timeout = NULL); int trywrlock (); int unlock (); diff --git a/winsup/doc/new-features.xml b/winsup/doc/new-features.xml index d7acd9b38..23673d1e0 100644 --- a/winsup/doc/new-features.xml +++ b/winsup/doc/new-features.xml @@ -9,7 +9,12 @@ -New APIs: explicit_bzero, pthread_mutex_timedwait. +New APIs: explicit_bzero. + + + +New APIs: pthread_mutex_timedwait, pthread_rwlock_timedrdlock, +pthread_rwlock_timedwrlock. diff --git a/winsup/doc/posix.xml b/winsup/doc/posix.xml index c9f4f00ec..a2fffeebf 100644 --- a/winsup/doc/posix.xml +++ b/winsup/doc/posix.xml @@ -723,6 +723,8 @@ also IEEE Std 1003.1-2008 (POSIX.1-2008). pthread_rwlock_destroy pthread_rwlock_init pthread_rwlock_rdlock + pthread_rwlock_timedrdlock + pthread_rwlock_timedwrlock pthread_rwlock_tryrdlock pthread_rwlock_trywrlock pthread_rwlock_unlock @@ -1575,8 +1577,6 @@ also IEEE Std 1003.1-2008 (POSIX.1-2008). pthread_mutexattr_getrobust pthread_mutexattr_setrobust pthread_mutex_consistent - pthread_rwlock_timedrdlock - pthread_rwlock_timedwrlock putmsg setnetent sigtimedwait