diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 7419f47b0..011d47bd6 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,24 @@ +2011-07-21 Yaakov Selkowitz + + * cygwin.din (pthread_condattr_getclock): Export. + (pthread_condattr_setclock): Export. + * posix.sgml (std-notimpl): Move pthread_condattr_getclock and + pthread_condattr_setclock from here... + (std-susv4): ... to here. + * sysconf.cc (sca): Set _SC_CLOCK_SELECTION to _POSIX_CLOCK_SELECTION. + * thread.cc: (pthread_condattr::pthread_condattr): Initialize clock_id. + (pthread_cond::pthread_cond): Initialize clock_id. + (pthread_cond_timedwait): Use clock_gettime() instead of gettimeofday() + in order to support all allowed clocks. + (pthread_condattr_getclock): New function. + (pthread_condattr_setclock): New function. + * thread.h (class pthread_condattr): Add clock_id member. + (class pthread_cond): Ditto. + * include/pthread.h: Remove obsolete comment. + (pthread_condattr_getclock): Declare. + (pthread_condattr_setclock): Declare. + * include/cygwin/version.h (CYGWIN_VERSION_API_MINOR): Bump. + 2011-07-18 Yaakov Selkowitz * sysconf.cc (sca): Return -1 for _SC_THREAD_ROBUST_PRIO_INHERIT, diff --git a/winsup/cygwin/cygwin.din b/winsup/cygwin/cygwin.din index 0484d8d18..eeb040886 100644 --- a/winsup/cygwin/cygwin.din +++ b/winsup/cygwin/cygwin.din @@ -1209,8 +1209,10 @@ pthread_cond_signal SIGFE pthread_cond_timedwait SIGFE pthread_cond_wait SIGFE pthread_condattr_destroy SIGFE +pthread_condattr_getclock SIGFE pthread_condattr_getpshared SIGFE pthread_condattr_init SIGFE +pthread_condattr_setclock SIGFE pthread_condattr_setpshared SIGFE pthread_continue SIGFE pthread_create SIGFE diff --git a/winsup/cygwin/include/cygwin/version.h b/winsup/cygwin/include/cygwin/version.h index f8e6f1069..9ed8db911 100644 --- a/winsup/cygwin/include/cygwin/version.h +++ b/winsup/cygwin/include/cygwin/version.h @@ -417,12 +417,13 @@ details. */ 247: Export error, error_at_line, error_message_count, error_one_per_line, error_print_progname. 248: Export __fpurge. + 249: Export pthread_condattr_getclock, pthread_condattr_setclock. */ /* Note that we forgot to bump the api for ualarm, strtoll, strtoull */ #define CYGWIN_VERSION_API_MAJOR 0 -#define CYGWIN_VERSION_API_MINOR 248 +#define CYGWIN_VERSION_API_MINOR 249 /* There is also a compatibity version number associated with the shared memory regions. It is incremented when incompatible diff --git a/winsup/cygwin/include/pthread.h b/winsup/cygwin/include/pthread.h index 4ed53ab08..8aa734a63 100644 --- a/winsup/cygwin/include/pthread.h +++ b/winsup/cygwin/include/pthread.h @@ -27,12 +27,6 @@ extern "C" /* Defines. (These are correctly defined here as per http://www.opengroup.org/onlinepubs/7908799/xsh/pthread.h.html */ -/* FIXME: this should allocate a new cond variable, and return the value that - would normally be written to the passed parameter of pthread_cond_init(lvalue, NULL); */ -/* #define PTHREAD_COND_INITIALIZER 0 */ - -/* the default : joinable */ - #define PTHREAD_CANCEL_ASYNCHRONOUS 1 /* defaults are enable, deferred */ #define PTHREAD_CANCEL_ENABLE 0 @@ -132,8 +126,10 @@ int pthread_cond_timedwait (pthread_cond_t *, pthread_mutex_t *, const struct timespec *); int pthread_cond_wait (pthread_cond_t *, pthread_mutex_t *); int pthread_condattr_destroy (pthread_condattr_t *); +int pthread_condattr_getclock (const pthread_condattr_t *, clockid_t *); int pthread_condattr_getpshared (const pthread_condattr_t *, int *); int pthread_condattr_init (pthread_condattr_t *); +int pthread_condattr_setclock (pthread_condattr_t *, clockid_t); int pthread_condattr_setpshared (pthread_condattr_t *, int); int pthread_create (pthread_t *, const pthread_attr_t *, diff --git a/winsup/cygwin/posix.sgml b/winsup/cygwin/posix.sgml index 8e509f640..1b122ebd3 100644 --- a/winsup/cygwin/posix.sgml +++ b/winsup/cygwin/posix.sgml @@ -554,8 +554,10 @@ also IEEE Std 1003.1-2008 (POSIX.1-2008). pthread_cond_timedwait pthread_cond_wait pthread_condattr_destroy + pthread_condattr_getclock pthread_condattr_getpshared pthread_condattr_init + pthread_condattr_setclock pthread_condattr_setpshared pthread_create pthread_detach @@ -1390,8 +1392,6 @@ also IEEE Std 1003.1-2008 (POSIX.1-2008). posix_typed_[...] powl pthread_barrier[...] - pthread_condattr_getclock - pthread_condattr_setclock pthread_mutexattr_getrobust pthread_mutexattr_setrobust pthread_mutex_consistent diff --git a/winsup/cygwin/sysconf.cc b/winsup/cygwin/sysconf.cc index cdb86ab75..f691b4568 100644 --- a/winsup/cygwin/sysconf.cc +++ b/winsup/cygwin/sysconf.cc @@ -158,7 +158,7 @@ static struct {cons, {c:BC_DIM_MAX}}, /* 58, _SC_BC_DIM_MAX */ {cons, {c:BC_SCALE_MAX}}, /* 59, _SC_BC_SCALE_MAX */ {cons, {c:BC_STRING_MAX}}, /* 60, _SC_BC_STRING_MAX */ - {cons, {c:-1L}}, /* 61, _SC_CLOCK_SELECTION */ + {cons, {c:_POSIX_CLOCK_SELECTION}}, /* 61, _SC_CLOCK_SELECTION */ {nsup, {c:0}}, /* 62, _SC_COLL_WEIGHTS_MAX */ {cons, {c:_POSIX_CPUTIME}}, /* 63, _SC_CPUTIME */ {cons, {c:EXPR_NEST_MAX}}, /* 64, _SC_EXPR_NEST_MAX */ diff --git a/winsup/cygwin/thread.cc b/winsup/cygwin/thread.cc index 59e412f00..40dd5e4d1 100644 --- a/winsup/cygwin/thread.cc +++ b/winsup/cygwin/thread.cc @@ -1099,7 +1099,8 @@ pthread_attr::~pthread_attr () } pthread_condattr::pthread_condattr ():verifyable_object - (PTHREAD_CONDATTR_MAGIC), shared (PTHREAD_PROCESS_PRIVATE) + (PTHREAD_CONDATTR_MAGIC), shared (PTHREAD_PROCESS_PRIVATE), + clock_id (CLOCK_REALTIME) { } @@ -1124,17 +1125,21 @@ pthread_cond::init_mutex () pthread_cond::pthread_cond (pthread_condattr *attr) : verifyable_object (PTHREAD_COND_MAGIC), - shared (0), waiting (0), pending (0), sem_wait (NULL), - mtx_cond(NULL), next (NULL) + shared (0), clock_id (CLOCK_REALTIME), waiting (0), pending (0), + sem_wait (NULL), mtx_cond(NULL), next (NULL) { pthread_mutex *verifyable_mutex_obj; if (attr) - if (attr->shared != PTHREAD_PROCESS_PRIVATE) - { - magic = 0; - return; - } + { + clock_id = attr->clock_id; + + if (attr->shared != PTHREAD_PROCESS_PRIVATE) + { + magic = 0; + return; + } + } verifyable_mutex_obj = &mtx_in; if (!pthread_mutex::is_good_object (&verifyable_mutex_obj)) @@ -2716,7 +2721,7 @@ extern "C" int pthread_cond_timedwait (pthread_cond_t *cond, pthread_mutex_t *mutex, const struct timespec *abstime) { - struct timeval tv; + struct timespec tp; DWORD waitlength; myfault efault; @@ -2731,17 +2736,18 @@ pthread_cond_timedwait (pthread_cond_t *cond, pthread_mutex_t *mutex, || abstime->tv_nsec > 999999999) return EINVAL; - gettimeofday (&tv, NULL); + clock_gettime ((*cond)->clock_id, &tp); + /* Check for immediate timeout before converting to microseconds, since the resulting value can easily overflow long. This also allows to evaluate microseconds directly in DWORD. */ - if (tv.tv_sec > abstime->tv_sec - || (tv.tv_sec == abstime->tv_sec - && tv.tv_usec > abstime->tv_nsec / 1000)) + if (tp.tv_sec > abstime->tv_sec + || (tp.tv_sec == abstime->tv_sec + && tp.tv_nsec > abstime->tv_nsec)) return ETIMEDOUT; - waitlength = (abstime->tv_sec - tv.tv_sec) * 1000; - waitlength += (abstime->tv_nsec / 1000 - tv.tv_usec) / 1000; + waitlength = (abstime->tv_sec - tp.tv_sec) * 1000; + waitlength += (abstime->tv_nsec - tp.tv_nsec) / 1000000; return __pthread_cond_dowait (cond, mutex, waitlength); } @@ -2792,6 +2798,32 @@ pthread_condattr_setpshared (pthread_condattr_t *attr, int pshared) return 0; } +extern "C" int +pthread_condattr_getclock (const pthread_condattr_t *attr, clockid_t *clock_id) +{ + if (!pthread_condattr::is_good_object (attr)) + return EINVAL; + *clock_id = (*attr)->clock_id; + return 0; +} + +extern "C" int +pthread_condattr_setclock (pthread_condattr_t *attr, clockid_t clock_id) +{ + if (!pthread_condattr::is_good_object (attr)) + return EINVAL; + switch (clock_id) + { + case CLOCK_REALTIME: + case CLOCK_MONOTONIC: + break; + default: + return EINVAL; + } + (*attr)->clock_id = clock_id; + return 0; +} + extern "C" int pthread_condattr_destroy (pthread_condattr_t *condattr) { diff --git a/winsup/cygwin/thread.h b/winsup/cygwin/thread.h index d8e4319a4..728ccc0c1 100644 --- a/winsup/cygwin/thread.h +++ b/winsup/cygwin/thread.h @@ -488,6 +488,7 @@ class pthread_condattr: public verifyable_object public: static bool is_good_object(pthread_condattr_t const *); int shared; + clockid_t clock_id; pthread_condattr (); ~pthread_condattr (); @@ -504,6 +505,7 @@ public: static int init (pthread_cond_t *, const pthread_condattr_t *); int shared; + clockid_t clock_id; unsigned long waiting; unsigned long pending;