From e4ca1795ead89b5ae79557775163bee6b505ffcc Mon Sep 17 00:00:00 2001 From: David Reiss Date: Thu, 21 May 2009 02:28:19 +0000 Subject: [PATCH] cpp: Deal with systems without sched_get_priority_{min,max} (OpenBSD) Also make a few tweaks to configure.ac: - Check for clock_gettime in librt since it seems to be more widely available. - Make it clear which AC_CHECK_FUNCS are optional. git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@776927 13f79535-47bb-0310-9956-ffa450edef68 --- configure.ac | 12 ++++++++++-- lib/cpp/src/concurrency/PosixThreadFactory.cpp | 10 ++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/configure.ac b/configure.ac index 8fd63d5c..2c53ca0a 100644 --- a/configure.ac +++ b/configure.ac @@ -131,7 +131,12 @@ AC_CHECK_HEADERS([libintl.h]) AC_CHECK_HEADERS([malloc.h]) AC_CHECK_LIB(pthread, pthread_create) -AC_CHECK_LIB(rt, sched_get_priority_min) +dnl NOTE(dreiss): I haven't been able to find any really solid docs +dnl on what librt is and how it fits into various Unix systems. +dnl My best guess is that it is where glibc stashes its implementation +dnl of the POSIX Real-Time Extensions. This seems necessary on Linux, +dnl and we haven't yet found a system where this is a problem. +AC_CHECK_LIB(rt, clock_gettime) AC_TYPE_INT16_T AC_TYPE_INT32_T @@ -170,7 +175,6 @@ AC_FUNC_STRFTIME AC_FUNC_VPRINTF AC_CHECK_FUNCS([strtoul]) AC_CHECK_FUNCS([bzero]) -AC_CHECK_FUNCS([clock_gettime]) AC_CHECK_FUNCS([ftruncate]) AC_CHECK_FUNCS([gethostbyname]) AC_CHECK_FUNCS([gettimeofday]) @@ -186,6 +190,10 @@ AC_CHECK_FUNCS([strerror]) AC_CHECK_FUNCS([strstr]) AC_CHECK_FUNCS([strtol]) AC_CHECK_FUNCS([sqrt]) +dnl The following functions are optional. +AC_CHECK_FUNCS([clock_gettime]) +AC_CHECK_FUNCS([sched_get_priority_min]) +AC_CHECK_FUNCS([sched_get_priority_max]) AX_SIGNED_RIGHT_SHIFT diff --git a/lib/cpp/src/concurrency/PosixThreadFactory.cpp b/lib/cpp/src/concurrency/PosixThreadFactory.cpp index e48dce39..893dc80d 100644 --- a/lib/cpp/src/concurrency/PosixThreadFactory.cpp +++ b/lib/cpp/src/concurrency/PosixThreadFactory.cpp @@ -227,8 +227,14 @@ class PosixThreadFactory::Impl { */ static int toPthreadPriority(POLICY policy, PRIORITY priority) { int pthread_policy = toPthreadPolicy(policy); - int min_priority = sched_get_priority_min(pthread_policy); - int max_priority = sched_get_priority_max(pthread_policy); + int min_priority = 0; + int max_priority = 0; +#ifdef HAVE_SCHED_GET_PRIORITY_MIN + min_priority = sched_get_priority_min(pthread_policy); +#endif +#ifdef HAVE_SCHED_GET_PRIORITY_MAX + max_priority = sched_get_priority_max(pthread_policy); +#endif int quanta = (HIGHEST - LOWEST) + 1; float stepsperquanta = (max_priority - min_priority) / quanta; -- 2.17.1