Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.openwrt.org/project/libubox.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt12
-rw-r--r--uloop.c13
2 files changed, 23 insertions, 2 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index ab82270..b756247 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,4 +1,6 @@
cmake_minimum_required(VERSION 2.6)
+INCLUDE(CheckLibraryExists)
+INCLUDE(CheckFunctionExists)
PROJECT(ubox C)
ADD_DEFINITIONS(-Os -Wall -Werror --std=gnu99 -g3 -Wmissing-declarations)
@@ -14,6 +16,16 @@ SET(SOURCES avl.c avl-cmp.c blob.c blobmsg.c uloop.c usock.c ustream.c ustream-f
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)
diff --git a/uloop.c b/uloop.c
index ecf26ec..2de4feb 100644
--- a/uloop.c
+++ b/uloop.c
@@ -351,6 +351,15 @@ int uloop_timeout_add(struct uloop_timeout *timeout)
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;
@@ -358,7 +367,7 @@ int uloop_timeout_set(struct uloop_timeout *timeout, int msecs)
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;
@@ -521,7 +530,7 @@ void uloop_run(void)
uloop_setup_signals();
while(!uloop_cancelled)
{
- gettimeofday(&tv, NULL);
+ uloop_gettime(&tv);
uloop_process_timeouts(&tv);
if (uloop_cancelled)
break;