forked from Mirrors/freeswitch
libzrtp: update zrtp_sleep for modern libc
usleep is deprecated and disabled in glibc 2.12 unless requested. Use nanosleep instead if available. This fixes the following compiler warning: ./src/zrtp_iface_scheduler.c: In function 'zrtp_sleep': ./src/zrtp_iface_scheduler.c:96:2: warning: implicit declaration of function 'usleep' [-Wimplicit-function-declaration] usleep(msec*1000); ^
This commit is contained in:
parent
98502947c8
commit
21c145b108
@ -68,7 +68,7 @@ AC_C_CONST
|
|||||||
# Checks for library functions.
|
# Checks for library functions.
|
||||||
AC_FUNC_MALLOC
|
AC_FUNC_MALLOC
|
||||||
AC_CHECK_FUNCS([memset memcpy malloc free])
|
AC_CHECK_FUNCS([memset memcpy malloc free])
|
||||||
AC_CHECK_FUNCS([usleep])
|
AC_CHECK_FUNCS([usleep nanosleep])
|
||||||
AC_CHECK_FUNCS([fopen fread])
|
AC_CHECK_FUNCS([fopen fread])
|
||||||
AC_CHECK_FUNCS([pthread_mutex_lock pthread_mutex_unlock pthread_mutex_init pthread_mutex_destroy])
|
AC_CHECK_FUNCS([pthread_mutex_lock pthread_mutex_unlock pthread_mutex_init pthread_mutex_destroy])
|
||||||
AC_CHECK_FUNCS([pthread_attr_init pthread_attr_setdetachstate pthread_create])
|
AC_CHECK_FUNCS([pthread_attr_init pthread_attr_setdetachstate pthread_create])
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
* Viktor Krykun <v.krikun at zfoneproject.com>
|
* Viktor Krykun <v.krikun at zfoneproject.com>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#define _POSIX_C_SOURCE 199309L /* for struct timespec */
|
||||||
#include "zrtp.h"
|
#include "zrtp.h"
|
||||||
|
|
||||||
#if (defined(ZRTP_USE_BUILTIN_SCEHDULER) && (ZRTP_USE_BUILTIN_SCEHDULER ==1))
|
#if (defined(ZRTP_USE_BUILTIN_SCEHDULER) && (ZRTP_USE_BUILTIN_SCEHDULER ==1))
|
||||||
@ -80,11 +81,15 @@ int zrtp_thread_create(zrtp_thread_routine_t start_routine, void *arg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#elif (ZRTP_PLATFORM == ZP_LINUX) || (ZRTP_PLATFORM == ZP_DARWIN) || (ZRTP_PLATFORM == ZP_BSD) || (ZRTP_PLATFORM == ZP_ANDROID)
|
#elif (ZRTP_PLATFORM == ZP_LINUX) || (ZRTP_PLATFORM == ZP_DARWIN) || (ZRTP_PLATFORM == ZP_BSD) || (ZRTP_PLATFORM == ZP_ANDROID)
|
||||||
#if ZRTP_HAVE_UNISTD_H == 1
|
/* POSIX.1-2008 removes usleep, so use nanosleep instead when available */
|
||||||
|
#if ZRTP_HAVE_NANOSLEEP
|
||||||
|
#include <time.h> /* for nanosleep */
|
||||||
|
#elif ZRTP_HAVE_UNISTD_H == 1
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#else
|
#else
|
||||||
#error "Used environment dosn't have <unistd.h> - zrtp_scheduler can't be build."
|
#error "Used environment dosn't have <unistd.h> - zrtp_scheduler can't be build."
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if ZRTP_HAVE_PTHREAD_H == 1
|
#if ZRTP_HAVE_PTHREAD_H == 1
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#else
|
#else
|
||||||
@ -93,7 +98,14 @@ int zrtp_thread_create(zrtp_thread_routine_t start_routine, void *arg)
|
|||||||
|
|
||||||
int zrtp_sleep(unsigned int msec)
|
int zrtp_sleep(unsigned int msec)
|
||||||
{
|
{
|
||||||
|
#if ZRTP_HAVE_NANOSLEEP
|
||||||
|
struct timespec delay;
|
||||||
|
delay.tv_sec = msec / 1000;
|
||||||
|
delay.tv_nsec = (msec % 1000) * 1000000;
|
||||||
|
while (nanosleep(&delay, &delay)) ;
|
||||||
|
#else
|
||||||
usleep(msec*1000);
|
usleep(msec*1000);
|
||||||
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user