cmake_minimum_required(VERSION 2.6)
+INCLUDE(CheckLibraryExists)
+INCLUDE(CheckFunctionExists)
PROJECT(ubox C)
ADD_DEFINITIONS(-Os -Wall -Werror --std=gnu99 -g3 -Wmissing-declarations)
ADD_LIBRARY(ubox SHARED ${SOURCES})
+SET(LIBS)
+CHECK_FUNCTION_EXISTS(clock_gettime HAVE_GETTIME)
+IF(NOT HAVE_GETTIME)
+ CHECK_LIBRARY_EXISTS(rt clock_gettime "" NEED_GETTIME)
+ IF(NEED_GETTIME)
+ TARGET_LINK_LIBRARIES(ubox rt)
+ ENDIF()
+ENDIF()
+
+
SET(CMAKE_INSTALL_PREFIX /usr)
FILE(GLOB headers *.h)
return 0;
}
+static void uloop_gettime(struct timeval *tv)
+{
+ struct timespec ts;
+
+ clock_gettime(CLOCK_MONOTONIC, &ts);
+ tv->tv_sec = ts.tv_sec;
+ tv->tv_usec = ts.tv_nsec / 1000;
+}
+
int uloop_timeout_set(struct uloop_timeout *timeout, int msecs)
{
struct timeval *time = &timeout->time;
if (timeout->pending)
uloop_timeout_cancel(timeout);
- gettimeofday(&timeout->time, NULL);
+ uloop_gettime(&timeout->time);
time->tv_sec += msecs / 1000;
time->tv_usec += (msecs % 1000) * 1000;
uloop_setup_signals();
while(!uloop_cancelled)
{
- gettimeofday(&tv, NULL);
+ uloop_gettime(&tv);
uloop_process_timeouts(&tv);
if (uloop_cancelled)
break;