]> sourceware.org Git - newlib-cygwin.git/commitdiff
cygwin: Implement pthread_mutex_timedlock
authorCorinna Vinschen <corinna@vinschen.de>
Thu, 3 Aug 2017 17:13:21 +0000 (19:13 +0200)
committerCorinna Vinschen <corinna@vinschen.de>
Thu, 3 Aug 2017 17:13:21 +0000 (19:13 +0200)
- pthread_mutex::lock now takes a PLARGE_INTEGER timeout pointer
  and uses that in the call to cygwait.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
winsup/cygwin/common.din
winsup/cygwin/include/cygwin/version.h
winsup/cygwin/include/pthread.h
winsup/cygwin/thread.cc
winsup/cygwin/thread.h

index 73e676841277627848494984bddc50d37677d519..9c8da379dd05015296c342ed4c72882414f1b6be 100644 (file)
@@ -1068,6 +1068,7 @@ pthread_mutex_getprioceiling SIGFE
 pthread_mutex_init SIGFE
 pthread_mutex_lock SIGFE
 pthread_mutex_setprioceiling SIGFE
+pthread_mutex_timedlock SIGFE
 pthread_mutex_trylock SIGFE
 pthread_mutex_unlock SIGFE
 pthread_mutexattr_destroy SIGFE
index ce548b13a8e0c6c5e7cb7bcca34f53a27b6c9b15..c258dc19540a5649f87aa4a6b23d8b7e05771261 100644 (file)
@@ -479,12 +479,13 @@ details. */
   312: Export strverscmp, versionsort.
   313: Export fls, flsl, flsll.
   314: Export explicit_bzero.
+  315: Export pthread_mutex_timedlock.
 
   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 314
+#define CYGWIN_VERSION_API_MINOR 315
 
 /* There is also a compatibity version number associated with the shared memory
    regions.  It is incremented when incompatible changes are made to the shared
index 47ee6bd651a16958b31fd0e681955e83082c56fe..9e8eb6f2bcb760d9adb196b1f1c83cfcaeed5c0d 100644 (file)
@@ -163,6 +163,7 @@ int pthread_mutex_getprioceiling (const pthread_mutex_t *, int *);
 int pthread_mutex_init (pthread_mutex_t *, const pthread_mutexattr_t *);
 int pthread_mutex_lock (pthread_mutex_t *);
 int pthread_mutex_setprioceiling (pthread_mutex_t *, int, int *);
+int pthread_mutex_timedlock (pthread_mutex_t *, const struct timespec *);
 int pthread_mutex_trylock (pthread_mutex_t *);
 int pthread_mutex_unlock (pthread_mutex_t *);
 int pthread_mutexattr_destroy (pthread_mutexattr_t *);
index c6048534bea9eb3f48d59f2480407c5f217e0524..c06c077c8c5c21cbe5298e08880f32d0021f22fd 100644 (file)
@@ -1765,7 +1765,7 @@ pthread_mutex::~pthread_mutex ()
 }
 
 int
-pthread_mutex::lock ()
+pthread_mutex::lock (PLARGE_INTEGER timeout)
 {
   pthread_t self = ::pthread_self ();
   int result = 0;
@@ -1775,7 +1775,7 @@ pthread_mutex::lock ()
   else if (type == PTHREAD_MUTEX_NORMAL /* potentially causes deadlock */
           || !pthread::equal (owner, self))
     {
-      cygwait (win32_obj_id, cw_infinite, cw_sig | cw_sig_restart);
+      cygwait (win32_obj_id, timeout, cw_sig | cw_sig_restart);
       set_owner (self);
     }
   else
@@ -3284,6 +3284,34 @@ pthread_mutex_lock (pthread_mutex_t *mutex)
   return (*mutex)->lock ();
 }
 
+extern "C" int
+pthread_mutex_timedlock (pthread_mutex_t *mutex, const struct timespec *abstime)
+{
+  LARGE_INTEGER timeout;
+
+  if (pthread_mutex::is_initializer (mutex))
+    pthread_mutex::init (mutex, NULL, *mutex);
+  if (!pthread_mutex::is_good_object (mutex))
+    return EINVAL;
+
+  /* According to SUSv3, abstime need not be checked for validity,
+     if the mutex can be locked immediately. */
+  if (!(*mutex)->trylock ())
+    return 0;
+
+  __try
+    {
+      int err = pthread_convert_abstime (CLOCK_REALTIME, abstime, &timeout);
+      if (err)
+       return err;
+
+      return (*mutex)->lock (&timeout);
+    }
+  __except (NO_ERROR) {}
+  __endtry
+  return EINVAL;
+}
+
 extern "C" int
 pthread_mutex_trylock (pthread_mutex_t *mutex)
 {
index 9bb8618243d596dae6a1bc7668844fd35168d7a5..88586ac4e184c4cf3b15643f84bcdbc4f1246942 100644 (file)
@@ -267,7 +267,7 @@ public:
   static bool is_initializer_or_object (pthread_mutex_t const *);
   static bool is_initializer_or_bad_object (pthread_mutex_t const *);
 
-  int lock ();
+  int lock (PLARGE_INTEGER timeout = NULL);
   int trylock ();
   int unlock ();
   int destroy ();
This page took 0.040248 seconds and 5 git commands to generate.