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>
This commit is contained in:
Corinna Vinschen 2018-06-27 17:56:59 +02:00
parent 006520ca2b
commit 732e0b395d
7 changed files with 42 additions and 11 deletions

View File

@ -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

View File

@ -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

View File

@ -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);

View File

@ -41,12 +41,6 @@ pthread_exit (void *value_ptr)
__builtin_unreachable (); /* FIXME: don't know why this is necessary */
}
int
pthread_join (pthread_t thread, void **return_val)
{
return pthread::join (&thread, (void **) return_val);
}
int
pthread_detach (pthread_t thread)
{

View File

@ -1,7 +1,8 @@
What's new:
-----------
- New API: clearenv.
- New API: clearenv, pthread_tryjoin_np, pthread_timedjoin_np.
What changed:
-------------

View File

@ -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;
@ -2574,6 +2579,32 @@ pthread_convert_abstime (clockid_t clock_id, const struct timespec *abstime,
return 0;
}
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)
{

View File

@ -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);