+int mainloop_gettime(struct timeval *val)
+{
+#ifdef _POSIX_MONOTONIC_CLOCK
+ struct timespec spec;
+ int ret;
+
+ ret=clock_gettime(CLOCK_MONOTONIC, &spec);
+
+ val->tv_sec=spec.tv_sec;
+ val->tv_usec=spec.tv_nsec/1000;
+
+ return ret;
+#else
+ return gettimeofday(&val, NULL);
+#endif
+}
+
+