From 306b332d47146e73cd5378b3d93a68ed5be2e7a1 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 30 Jun 2011 14:36:52 -0500 Subject: [PATCH] add --enable-timerfd-wrapper to wrap timefd syscalls for platforms with the right kernel and wrong libc --- src/include/timerfd_wrap.h | 93 ++++++++++++++++++++++++++++++++++++++ src/switch_time.c | 5 ++ 2 files changed, 98 insertions(+) create mode 100644 src/include/timerfd_wrap.h diff --git a/src/include/timerfd_wrap.h b/src/include/timerfd_wrap.h new file mode 100644 index 0000000000..bb751c93a2 --- /dev/null +++ b/src/include/timerfd_wrap.h @@ -0,0 +1,93 @@ +/* + * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application + * Copyright (C) 2005-2011, Anthony Minessale II + * + * Version: MPL 1.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application + * + * The Initial Developer of the Original Code is + * Anthony Minessale II + * Portions created by the Initial Developer are Copyright (C) + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * Anthony Minessale II + * + * timerfd_wrap.h -- timerfd syscall wrapper + * + */ +/*! \file timerfd_wrap.h + \brief timerfd syscall wrapper +*/ + +#ifndef TIMERFD_WRAP_H +#define TIMERFD_WRAP_H +SWITCH_BEGIN_EXTERN_C + +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +#ifndef __NR_timerfd +#if defined(__x86_64__) +#define __NR_timerfd_create 283 +#define __NR_timerfd_settime 286 +#define __NR_timerfd_gettime 287 +#elif defined(__i386__) +#define __NR_timerfd_create 322 +#define __NR_timerfd_settime 325 +#define __NR_timerfd_gettime 326 +#else +#error invalid system +#endif +#endif + +#define TFD_TIMER_ABSTIME (1 << 0) + +int timerfd_create(int clockid, int flags) +{ + + return syscall(__NR_timerfd_create, clockid, flags); +} + +int timerfd_settime(int ufc, int flags, const struct itimerspec *utmr, struct itimerspec *otmr) +{ + + return syscall(__NR_timerfd_settime, ufc, flags, utmr, otmr); +} + +int timerfd_gettime(int ufc, struct itimerspec *otmr) +{ + + return syscall(__NR_timerfd_gettime, ufc, otmr); +} + +SWITCH_END_EXTERN_C + +#endif diff --git a/src/switch_time.c b/src/switch_time.c index 7c10233790..47fd09b8b9 100644 --- a/src/switch_time.c +++ b/src/switch_time.c @@ -38,6 +38,11 @@ #include #endif +#ifdef TIMERFD_WRAP +#include +#define HAVE_TIMERFD_CREATE +#endif + //#if defined(DARWIN) #define DISABLE_1MS_COND //#endif