From: <pk...@us...> - 2007-01-15 00:02:40
|
Revision: 830 http://svn.sourceforge.net/conky/?rev=830&view=rev Author: pkovacs Date: 2007-01-14 16:02:38 -0800 (Sun, 14 Jan 2007) Log Message: ----------- fallback to gettimeofday () if no clock_gettime () (mac os) Modified Paths: -------------- trunk/conky1/ChangeLog trunk/conky1/configure.ac.in trunk/conky1/src/linux.c trunk/conky1/src/timed_thread.c Modified: trunk/conky1/ChangeLog =================================================================== --- trunk/conky1/ChangeLog 2007-01-10 02:57:58 UTC (rev 829) +++ trunk/conky1/ChangeLog 2007-01-15 00:02:38 UTC (rev 830) @@ -1,5 +1,8 @@ # $Id$ +2007-01-14 + * Fallback to gettimeofday() when clock_gettime () not available (mac os). + 2007-01-09 * API change (timing in milliseconds) for dexter_timedsampler_new (). Modified: trunk/conky1/configure.ac.in =================================================================== --- trunk/conky1/configure.ac.in 2007-01-10 02:57:58 UTC (rev 829) +++ trunk/conky1/configure.ac.in 2007-01-15 00:02:38 UTC (rev 830) @@ -430,8 +430,11 @@ dnl AC_CHECK_FUNCS([calloc malloc free popen sysinfo getloadavg]) -AC_SEARCH_LIBS(clock_gettime, [rt], [], AC_MSG_ERROR([clock_gettime() not found])) +AC_SEARCH_LIBS(clock_gettime, [rt], + [AC_DEFINE(HAVE_CLOCK_GETTIME, 1, [Define if you have clock_gettime()])], + [AC_CHECK_FUNCS([gettimeofday], [], [AC_MSG_ERROR([gettimeofday() not available!])])], []) + dnl dnl Check for zlib dnl Modified: trunk/conky1/src/linux.c =================================================================== --- trunk/conky1/src/linux.c 2007-01-10 02:57:58 UTC (rev 829) +++ trunk/conky1/src/linux.c 2007-01-15 00:02:38 UTC (rev 830) @@ -16,6 +16,9 @@ #include <sys/types.h> #include <sys/sysinfo.h> #include <sys/stat.h> +#ifndef HAVE_CLOCK_GETTIME +#include <sys/time.h> +#endif #include <fcntl.h> #include <unistd.h> // #include <assert.h> @@ -2085,7 +2088,19 @@ /* record data packet arrival time */ g_mutex_lock (packet_mutex); +#ifdef HAVE_CLOCK_GETTIME clock_gettime (CLOCK_REALTIME, &packet_arrival_time); +#else + { + /* fallback to gettimeofday () */ + struct timeval tv; + if (gettimeofday (&tv, NULL) == 0) + { + packet_arrival_time.tv_sec = tv.tv_sec; + packet_arrival_time.tv_nsec = tv.tv_usec * 1000; + } + } +#endif g_mutex_unlock (packet_mutex); #ifdef DEBUG fprintf(stderr, "Conky: data packet arrived\n"); Modified: trunk/conky1/src/timed_thread.c =================================================================== --- trunk/conky1/src/timed_thread.c 2007-01-10 02:57:58 UTC (rev 829) +++ trunk/conky1/src/timed_thread.c 2007-01-15 00:02:38 UTC (rev 830) @@ -28,6 +28,9 @@ #include <stdlib.h> #include <stdio.h> #include <time.h> +#ifndef HAVE_CLOCK_GETTIME +#include <sys/time.h> +#endif #include "timed_thread.h" /* Abstraction layer for timed threads */ @@ -154,7 +157,22 @@ return (-1); /* could not acquire runnable_cond mutex, so tell caller to exit thread */ /* get the absolute time in the future we stop waiting for condition to signal */ +#ifdef HAVE_CLOCK_GETTIME clock_gettime (CLOCK_REALTIME, &abstime); +#else + { + /* fallback to gettimeofday () */ + struct timeval tv; + if (gettimeofday (&tv, NULL) != 0) + { + pthread_mutex_unlock (&p_timed_thread->runnable_mutex); + return (-1); + } + + abstime.tv_sec = tv.tv_sec; + abstime.tv_nsec = tv.tv_usec * 1000; + } +#endif /* seconds portion of the microseconds interval */ reltime.tv_sec = (time_t)(p_timed_thread->interval_usecs / 1000000); /* remaining microseconds convert to nanoseconds */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |