This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
[RFC 1/2] gthread: Add __gthread_cond_timedwaitonclock
- From: Mike Crowe <mac at mcrowe dot com>
- To: libstdc++ at gcc dot gnu dot org, gcc-patches at gcc dot gnu dot org
- Cc: Mike Crowe <mac at mcrowe dot com>
- Date: Mon, 6 Jul 2015 13:55:39 +0100
- Subject: [RFC 1/2] gthread: Add __gthread_cond_timedwaitonclock
- Authentication-results: sourceware.org; auth=none
If glibc contains pthread_cond_timedwaitonclock_np then provide
__gthread_cond_timedwaitonclock so that condition variables can be
waited on using any system-supported clock.
(I have a patch that adds pthread_cond_timedwaitonclock_np to glibc
ready to submit but I wanted to get feedback on this part of the change
before submitting the glibc patch. See
https://gitlab.com/mikecrowe/glibc-monotonic .)
Signed-off-by: Mike Crowe <mac@mcrowe.com>
---
libgcc/gthr-posix.h | 22 +++++++++++++
libstdc++-v3/acinclude.m4 | 30 +++++++++++++++++
libstdc++-v3/config.h.in | 3 ++
libstdc++-v3/configure | 83 +++++++++++++++++++++++++++++++++++++++++++++++
libstdc++-v3/configure.ac | 3 ++
5 files changed, 141 insertions(+)
diff --git a/libgcc/gthr-posix.h b/libgcc/gthr-posix.h
index fb59816..0e01866 100644
--- a/libgcc/gthr-posix.h
+++ b/libgcc/gthr-posix.h
@@ -33,6 +33,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
#define __GTHREADS_CXX0X 1
#include <pthread.h>
+#include <time.h>
#if ((defined(_LIBOBJC) || defined(_LIBOBJC_WEAK)) \
|| !defined(_GTHREAD_USE_MUTEX_TIMEDLOCK))
@@ -44,6 +45,11 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
# endif
#endif
+
+#if defined(_GLIBCXX_USE_PTHREAD_COND_TIMEDWAITONCLOCK_NP)
+# define _GTHREAD_USE_COND_TIMEDWAITONCLOCK 1
+#endif
+
typedef pthread_t __gthread_t;
typedef pthread_key_t __gthread_key_t;
typedef pthread_once_t __gthread_once_t;
@@ -51,6 +57,9 @@ typedef pthread_mutex_t __gthread_mutex_t;
typedef pthread_mutex_t __gthread_recursive_mutex_t;
typedef pthread_cond_t __gthread_cond_t;
typedef struct timespec __gthread_time_t;
+typedef clockid_t __gthread_clockid_t;
+
+#define __GTHREAD_CLOCK_MONOTONIC CLOCK_MONOTONIC
/* POSIX like conditional variables are supported. Please look at comments
in gthr.h for details. */
@@ -126,6 +135,9 @@ __gthrw(pthread_cond_broadcast)
__gthrw(pthread_cond_signal)
__gthrw(pthread_cond_wait)
__gthrw(pthread_cond_timedwait)
+#if _GTHREAD_USE_COND_TIMEDWAITONCLOCK
+__gthrw(pthread_cond_timedwaitonclock_np)
+#endif
__gthrw(pthread_cond_destroy)
__gthrw(pthread_key_create)
@@ -871,6 +883,16 @@ __gthread_cond_timedwait (__gthread_cond_t *__cond, __gthread_mutex_t *__mutex,
return __gthrw_(pthread_cond_timedwait) (__cond, __mutex, __abs_timeout);
}
+#if _GTHREAD_USE_COND_TIMEDWAITONCLOCK
+static inline int
+__gthread_cond_timedwaitonclock (__gthread_cond_t *__cond, __gthread_mutex_t *__mutex,
+ __gthread_clockid_t __clockid,
+ const __gthread_time_t *__abs_timeout)
+{
+ return __gthrw_(pthread_cond_timedwaitonclock_np) (__cond, __mutex, __clockid, __abs_timeout);
+}
+#endif
+
static inline int
__gthread_cond_wait_recursive (__gthread_cond_t *__cond,
__gthread_recursive_mutex_t *__mutex)
diff --git a/libstdc++-v3/acinclude.m4 b/libstdc++-v3/acinclude.m4
index 11f48f9..6207719 100644
--- a/libstdc++-v3/acinclude.m4
+++ b/libstdc++-v3/acinclude.m4
@@ -3652,6 +3652,36 @@ AC_DEFUN([GLIBCXX_CHECK_PTHREADS_NUM_PROCESSORS_NP], [
])
dnl
+dnl Check whether pthread_cond_timedwaitonclock_np is available in <pthread.h>, and define _GLIBCXX_USE_PTHREAD_COND_TIMEDWAITONCLOCK_NP.
+dnl
+AC_DEFUN([GLIBCXX_CHECK_PTHREAD_COND_TIMEDWAITONCLOCK_NP], [
+
+ AC_LANG_SAVE
+ AC_LANG_CPLUSPLUS
+ ac_save_CXXFLAGS="$CXXFLAGS"
+ CXXFLAGS="$CXXFLAGS -fno-exceptions"
+ ac_save_LIBS="$LIBS"
+ LIBS="$LIBS -lpthread"
+
+ AC_MSG_CHECKING([for pthread_cond_timedwaitonclock_np])
+ AC_CACHE_VAL(glibcxx_cv_PTHREAD_COND_TIMEDWAITONCLOCK_NP, [
+ GCC_TRY_COMPILE_OR_LINK(
+ [#include <pthread.h>],
+ [pthread_mutex_t mutex; pthread_cond_t cond; struct timespec ts; int n = pthread_cond_timedwaitonclock_np(&cond, &mutex, 0, &ts);],
+ [glibcxx_cv_PTHREAD_COND_TIMEDWAITONCLOCK_NP=yes],
+ [glibcxx_cv_PTHREAD_COND_TIMEDWAITONCLOCK_NP=no])
+ ])
+ if test $glibcxx_cv_PTHREAD_COND_TIMEDWAITONCLOCK_NP = yes; then
+ AC_DEFINE(_GLIBCXX_USE_PTHREAD_COND_TIMEDWAITONCLOCK_NP, 1, [Define if pthread_cond_timedwaitonclock_np is available in <pthread.h>.])
+ fi
+ AC_MSG_RESULT($glibcxx_cv_PTHREAD_COND_TIMEDWAITONCLOCK_NP)
+
+ CXXFLAGS="$ac_save_CXXFLAGS"
+ LIBS="$ac_save_LIBS"
+ AC_LANG_RESTORE
+])
+
+dnl
dnl Check whether sysctl is available in <pthread.h>, and define _GLIBCXX_USE_SYSCTL_HW_NCPU.
dnl
AC_DEFUN([GLIBCXX_CHECK_SYSCTL_HW_NCPU], [
diff --git a/libstdc++-v3/config.h.in b/libstdc++-v3/config.h.in
index 337f614..a46efd8 100644
--- a/libstdc++-v3/config.h.in
+++ b/libstdc++-v3/config.h.in
@@ -869,6 +869,9 @@
/* Define if pthreads_num_processors_np is available in <pthread.h>. */
#undef _GLIBCXX_USE_PTHREADS_NUM_PROCESSORS_NP
+/* Define if pthread_cond_timedwaitonclock_np is available in <pthread.h>. */
+#undef _GLIBCXX_USE_PTHREAD_COND_TIMEDWAITONCLOCK_NP
+
/* Define if POSIX read/write locks are available in <gthr.h>. */
#undef _GLIBCXX_USE_PTHREAD_RWLOCK_T
diff --git a/libstdc++-v3/configure b/libstdc++-v3/configure
index e9521d6..19434c4 100755
--- a/libstdc++-v3/configure
+++ b/libstdc++-v3/configure
@@ -20220,6 +20220,89 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu
+# For pthread_cond_timedwaitonclock_np
+
+
+
+ ac_ext=cpp
+ac_cpp='$CXXCPP $CPPFLAGS'
+ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
+
+ ac_save_CXXFLAGS="$CXXFLAGS"
+ CXXFLAGS="$CXXFLAGS -fno-exceptions"
+ ac_save_LIBS="$LIBS"
+ LIBS="$LIBS -lpthread"
+
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking for pthread_cond_timedwaitonclock_np" >&5
+$as_echo_n "checking for pthread_cond_timedwaitonclock_np... " >&6; }
+ if test "${glibcxx_cv_PTHREAD_COND_TIMEDWAITONCLOCK_NP+set}" = set; then :
+ $as_echo_n "(cached) " >&6
+else
+
+ if test x$gcc_no_link = xyes; then
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+#include <pthread.h>
+int
+main ()
+{
+pthread_mutex_t mutex; pthread_cond_t cond; struct timespec ts; int n = pthread_cond_timedwaitonclock_np(&cond, &mutex, 0, &ts);
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_cxx_try_compile "$LINENO"; then :
+ glibcxx_cv_PTHREAD_COND_TIMEDWAITONCLOCK_NP=yes
+else
+ glibcxx_cv_PTHREAD_COND_TIMEDWAITONCLOCK_NP=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+else
+ if test x$gcc_no_link = xyes; then
+ as_fn_error "Link tests are not allowed after GCC_NO_EXECUTABLES." "$LINENO" 5
+fi
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+#include <pthread.h>
+int
+main ()
+{
+pthread_mutex_t mutex; pthread_cond_t cond; struct timespec ts; int n = pthread_cond_timedwaitonclock_np(&cond, &mutex, 0, &ts);
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_cxx_try_link "$LINENO"; then :
+ glibcxx_cv_PTHREAD_COND_TIMEDWAITONCLOCK_NP=yes
+else
+ glibcxx_cv_PTHREAD_COND_TIMEDWAITONCLOCK_NP=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+ conftest$ac_exeext conftest.$ac_ext
+fi
+
+fi
+
+ if test $glibcxx_cv_PTHREAD_COND_TIMEDWAITONCLOCK_NP = yes; then
+
+$as_echo "#define _GLIBCXX_USE_PTHREAD_COND_TIMEDWAITONCLOCK_NP 1" >>confdefs.h
+
+ fi
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $glibcxx_cv_PTHREAD_COND_TIMEDWAITONCLOCK_NP" >&5
+$as_echo "$glibcxx_cv_PTHREAD_COND_TIMEDWAITONCLOCK_NP" >&6; }
+
+ CXXFLAGS="$ac_save_CXXFLAGS"
+ LIBS="$ac_save_LIBS"
+ ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+
+
ac_fn_c_check_header_mongrel "$LINENO" "locale.h" "ac_cv_header_locale_h" "$ac_includes_default"
if test "x$ac_cv_header_locale_h" = x""yes; then :
diff --git a/libstdc++-v3/configure.ac b/libstdc++-v3/configure.ac
index 96ff16f..f59981c 100644
--- a/libstdc++-v3/configure.ac
+++ b/libstdc++-v3/configure.ac
@@ -218,6 +218,9 @@ GLIBCXX_ENABLE_LIBSTDCXX_TIME
# Check for tmpnam which is obsolescent in POSIX.1-2008
GLIBCXX_CHECK_TMPNAM
+# For pthread_cond_timedwaitonclock_np
+GLIBCXX_CHECK_PTHREAD_COND_TIMEDWAITONCLOCK_NP
+
AC_LC_MESSAGES
# For hardware_concurrency
--
2.1.4