public inbox for cygwin-cvs@sourceware.org
help / color / mirror / Atom feed
* [newlib-cygwin] Cygwin: Implement pthread_tryjoin_np and pthread_timedjoin_np
@ 2018-06-27 15:57 Corinna Vinschen
  0 siblings, 0 replies; only message in thread
From: Corinna Vinschen @ 2018-06-27 15:57 UTC (permalink / raw)
  To: cygwin-cvs

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

commit 732e0b395ddad021a9667aecca6a387e8a8a598d
Author: Corinna Vinschen <corinna@vinschen.de>
Date:   Wed Jun 27 17:56:59 2018 +0200

    Cygwin: Implement pthread_tryjoin_np and pthread_timedjoin_np
    
    - Move pthread_join to thread.cc to have all `join' calls in
      the same file (pthread_timedjoin_np needs pthread_convert_abstime
      which is static inline in thread.cc)
    - Bump API version
    
    Signed-off-by: Corinna Vinschen <corinna@vinschen.de>

Diff:
---
 winsup/cygwin/common.din               |  2 ++
 winsup/cygwin/include/cygwin/version.h |  3 ++-
 winsup/cygwin/include/pthread.h        |  2 ++
 winsup/cygwin/pthread.cc               |  6 ------
 winsup/cygwin/release/2.11.0           |  3 ++-
 winsup/cygwin/thread.cc                | 35 ++++++++++++++++++++++++++++++++--
 winsup/cygwin/thread.h                 |  2 +-
 7 files changed, 42 insertions(+), 11 deletions(-)

diff --git a/winsup/cygwin/common.din b/winsup/cygwin/common.din
index 426cf17..1e971cf 100644
--- a/winsup/cygwin/common.din
+++ b/winsup/cygwin/common.din
@@ -1135,6 +1135,8 @@ pthread_spin_trylock SIGFE
 pthread_spin_unlock SIGFE
 pthread_suspend SIGFE
 pthread_testcancel SIGFE
+pthread_timedjoin_np SIGFE
+pthread_tryjoin_np SIGFE
 pthread_yield = sched_yield SIGFE
 ptsname SIGFE
 ptsname_r SIGFE
diff --git a/winsup/cygwin/include/cygwin/version.h b/winsup/cygwin/include/cygwin/version.h
index 958acca..b461fa9 100644
--- a/winsup/cygwin/include/cygwin/version.h
+++ b/winsup/cygwin/include/cygwin/version.h
@@ -495,12 +495,13 @@ details. */
   324: Export sigtimedwait.
   325: Export catclose, catgets, catopen.
   326: Export clearenv
+  327: Export pthread_tryjoin_np, pthread_timedjoin_np.
 
   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 326
+#define CYGWIN_VERSION_API_MINOR 327
 
 /* 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/include/pthread.h b/winsup/cygwin/include/pthread.h
index fed6165..beaac59 100644
--- a/winsup/cygwin/include/pthread.h
+++ b/winsup/cygwin/include/pthread.h
@@ -154,6 +154,8 @@ int pthread_getcpuclockid (pthread_t, clockid_t *);
 int pthread_getschedparam (pthread_t, int *, struct sched_param *);
 void *pthread_getspecific (pthread_key_t);
 int pthread_join (pthread_t, void **);
+int pthread_tryjoin_np (pthread_t, void **);
+int pthread_timedjoin_np (pthread_t, void **, const struct timespec *);
 int pthread_key_create (pthread_key_t *, void (*)(void *));
 int pthread_key_delete (pthread_key_t);
 
diff --git a/winsup/cygwin/pthread.cc b/winsup/cygwin/pthread.cc
index b9da2ef..e7f87f9 100644
--- a/winsup/cygwin/pthread.cc
+++ b/winsup/cygwin/pthread.cc
@@ -42,12 +42,6 @@ pthread_exit (void *value_ptr)
 }
 
 int
-pthread_join (pthread_t thread, void **return_val)
-{
-  return pthread::join (&thread, (void **) return_val);
-}
-
-int
 pthread_detach (pthread_t thread)
 {
   return pthread::detach (&thread);
diff --git a/winsup/cygwin/release/2.11.0 b/winsup/cygwin/release/2.11.0
index e807b6e..b1aaaf3 100644
--- a/winsup/cygwin/release/2.11.0
+++ b/winsup/cygwin/release/2.11.0
@@ -1,7 +1,8 @@
 What's new:
 -----------
 
-- New API: clearenv.
+- New API: clearenv, pthread_tryjoin_np, pthread_timedjoin_np.
+
 
 What changed:
 -------------
diff --git a/winsup/cygwin/thread.cc b/winsup/cygwin/thread.cc
index 9f2e183..2734d17 100644
--- a/winsup/cygwin/thread.cc
+++ b/winsup/cygwin/thread.cc
@@ -2421,7 +2421,7 @@ pthread_attr_destroy (pthread_attr_t *attr)
 }
 
 int
-pthread::join (pthread_t *thread, void **return_val)
+pthread::join (pthread_t *thread, void **return_val, PLARGE_INTEGER timeout)
 {
    pthread_t joiner = self ();
 
@@ -2453,7 +2453,7 @@ pthread::join (pthread_t *thread, void **return_val)
       (*thread)->attr.joinable = PTHREAD_CREATE_DETACHED;
       (*thread)->mutex.unlock ();
 
-      switch (cygwait ((*thread)->win32_obj_id, cw_infinite,
+      switch (cygwait ((*thread)->win32_obj_id, timeout,
 		       cw_sig | cw_sig_restart | cw_cancel))
 	{
 	case WAIT_OBJECT_0:
@@ -2468,6 +2468,11 @@ pthread::join (pthread_t *thread, void **return_val)
 	  joiner->cancel_self ();
 	  // never reached
 	  break;
+	case WAIT_TIMEOUT:
+	  // set joined thread back to joinable since we got canceled
+	  (*thread)->joiner = NULL;
+	  (*thread)->attr.joinable = PTHREAD_CREATE_JOINABLE;
+	  return EBUSY;
 	default:
 	  // should never happen
 	  return EINVAL;
@@ -2575,6 +2580,32 @@ pthread_convert_abstime (clockid_t clock_id, const struct timespec *abstime,
 }
 
 extern "C" int
+pthread_join (pthread_t thread, void **return_val)
+{
+  return pthread::join (&thread, (void **) return_val, NULL);
+}
+
+extern "C" int
+pthread_tryjoin_np (pthread_t thread, void **return_val)
+{
+  LARGE_INTEGER timeout = { 0, 0 };
+
+  return pthread::join (&thread, (void **) return_val, &timeout);
+}
+
+extern "C" int
+pthread_timedjoin_np (pthread_t thread, void **return_val,
+		      const struct timespec *abstime)
+{
+  LARGE_INTEGER timeout;
+
+  int err = pthread_convert_abstime (CLOCK_REALTIME, abstime, &timeout);
+  if (err)
+    return err;
+  return pthread::join (&thread, (void **) return_val, &timeout);
+}
+
+extern "C" int
 pthread_getattr_np (pthread_t thread, pthread_attr_t *attr)
 {
   THREAD_BASIC_INFORMATION tbi;
diff --git a/winsup/cygwin/thread.h b/winsup/cygwin/thread.h
index 9f5e19b..4c6557a 100644
--- a/winsup/cygwin/thread.h
+++ b/winsup/cygwin/thread.h
@@ -375,7 +375,7 @@ public:
 
   /* API calls */
   static int cancel (pthread_t);
-  static int join (pthread_t * thread, void **return_val);
+  static int join (pthread_t * thread, void **return_val, PLARGE_INTEGER);
   static int detach (pthread_t * thread);
   static int create (pthread_t * thread, const pthread_attr_t * attr,
 			      void *(*start_routine) (void *), void *arg);


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2018-06-27 15:57 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-27 15:57 [newlib-cygwin] Cygwin: Implement pthread_tryjoin_np and pthread_timedjoin_np Corinna Vinschen

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).