summaryrefslogtreecommitdiffstats
path: root/lib/qtime.h
diff options
context:
space:
mode:
authorChris Hall <chris.hall@highwayman.com>2011-02-13 23:11:45 +0000
committerChris Hall <chris.hall@highwayman.com>2011-02-13 23:11:45 +0000
commit5cae7eea451f2b7d65b5892e2c1dafc70f8b836e (patch)
tree0fbd9679e9ae28e7d061b5bdda08756077415ecb /lib/qtime.h
parent64be6d766a65dc0749d17f5023d714678e9c96a6 (diff)
downloadquagga-5cae7eea451f2b7d65b5892e2c1dafc70f8b836e.tar.bz2
quagga-5cae7eea451f2b7d65b5892e2c1dafc70f8b836e.tar.xz
Second tranche of updates for pipework branch.
modified: bgpd/bgp_connection.c modified: bgpd/bgp_debug.c modified: bgpd/bgp_engine.h modified: bgpd/bgp_main.c modified: bgpd/bgp_packet.c modified: bgpd/bgp_peer.c modified: bgpd/bgp_route.c modified: bgpd/bgp_routemap.c modified: bgpd/bgp_session.c modified: bgpd/bgp_vty.c modified: bgpd/bgpd.c modified: bgpd/bgpd.h modified: configure.ac modified: isisd/dict.h modified: isisd/isis_misc.c modified: isisd/isis_routemap.c modified: isisd/isis_spf.c modified: lib/Makefile.am modified: lib/command.c modified: lib/command.h modified: lib/command_execute.h modified: lib/command_parse.c modified: lib/command_parse.h modified: lib/command_queue.c modified: lib/command_queue.h modified: lib/elstring.h modified: lib/heap.c modified: lib/if.c modified: lib/if.h modified: lib/keychain.c modified: lib/keystroke.c modified: lib/keystroke.h modified: lib/list_util.c modified: lib/list_util.h modified: lib/log.c modified: lib/log.h modified: lib/memory.c modified: lib/memory.h modified: lib/memtypes.c modified: lib/misc.h modified: lib/mqueue.c modified: lib/mqueue.h deleted: lib/node_type.h modified: lib/pthread_safe.c modified: lib/qfstring.c modified: lib/qiovec.c modified: lib/qiovec.h modified: lib/qpath.c modified: lib/qpnexus.c modified: lib/qpnexus.h modified: lib/qpselect.c modified: lib/qpthreads.h modified: lib/qstring.c modified: lib/qstring.h modified: lib/qtime.c modified: lib/qtime.h modified: lib/qtimers.c modified: lib/qtimers.h modified: lib/routemap.c modified: lib/symtab.h modified: lib/thread.h deleted: lib/uty.h modified: lib/vector.c modified: lib/vector.h modified: lib/version.h.in modified: lib/vio_fifo.c modified: lib/vio_fifo.h modified: lib/vio_lines.c modified: lib/vio_lines.h modified: lib/vty.c modified: lib/vty.h modified: lib/vty_cli.c modified: lib/vty_cli.h modified: lib/vty_io.c modified: lib/vty_io.h modified: lib/vty_io_basic.c modified: lib/vty_io_basic.h modified: lib/vty_io_file.c modified: lib/vty_io_file.h modified: lib/vty_io_shell.c modified: lib/vty_io_term.c modified: lib/vty_io_term.h modified: lib/vty_local.h modified: lib/vty_pipe.c modified: lib/workqueue.h modified: lib/zebra.h modified: ospf6d/ospf6_lsa.c modified: ripngd/ripngd.c modified: tests/test-list_util.c modified: tests/test-vector.c modified: vtysh/vtysh.c modified: vtysh/vtysh_config.c
Diffstat (limited to 'lib/qtime.h')
-rw-r--r--lib/qtime.h137
1 files changed, 52 insertions, 85 deletions
diff --git a/lib/qtime.h b/lib/qtime.h
index 38e9ac1a..94d468a8 100644
--- a/lib/qtime.h
+++ b/lib/qtime.h
@@ -23,14 +23,11 @@
#define _ZEBRA_QTIME_H
#include "misc.h"
-#include <stdlib.h>
+
#include <time.h>
#include <sys/time.h>
#include <unistd.h>
-#include "zassert.h"
-#include "config.h"
-
/*==============================================================================
* qtime_t -- signed 64-bit integer.
*
@@ -64,17 +61,13 @@ typedef qtime_t qtime_tod_t ; /* qtime_t value, timeofday time-base... */
/* Note that the time to convert may be a float. */
#define QTIME(s) ((qtime_t)((s) * (qtime_t)QTIME_SECOND))
-Inline qtime_t
-timespec2qtime(struct timespec* p_ts) ;
-
-Inline qtime_t
-timeval2qtime(struct timeval* p_tv) ;
-
-Inline struct timespec*
-qtime2timespec(struct timespec* p_ts, qtime_t qt) ;
-
-Inline struct timeval*
-qtime2timeval(struct timeval* p_tv, qtime_t qt) ;
+/*==============================================================================
+ * Conversion functions
+ */
+Inline qtime_t timespec2qtime(struct timespec* p_ts) ;
+Inline qtime_t timeval2qtime(struct timeval* p_tv) ;
+Inline struct timespec* qtime2timespec(struct timespec* p_ts, qtime_t qt) ;
+Inline struct timeval* qtime2timeval(struct timeval* p_tv, qtime_t qt) ;
/*==============================================================================
* Clocks.
@@ -93,44 +86,37 @@ qtime2timeval(struct timeval* p_tv, qtime_t qt) ;
* a manufactured equivalent using times() -- see qt_craft_monotonic().
*/
-Inline qtime_real_t
-qt_get_realtime(void) ; /* clock_gettime(CLOCK_REALTIME, ...) */
+Inline qtime_real_t qt_get_realtime(void) ;
+ /* clock_gettime(CLOCK_REALTIME, ...) */
+Inline qtime_mono_t qt_add_realtime(qtime_t interval) ;
+ /* qt_get_realtime() + interval */
-Inline qtime_mono_t
-qt_add_realtime(qtime_t interval) ; /* qt_get_realtime() + interval */
-
-Inline qtime_mono_t
-qt_get_monotonic(void) ; /* clock_gettime(CLOCK_MONOTONIC, ...) */
+Inline qtime_mono_t qt_get_monotonic(void) ;
+ /* clock_gettime(CLOCK_MONOTONIC, ...) */
/* OR equivalent using times() */
-Inline qtime_mono_t
-qt_add_monotonic(qtime_t interval) ; /* qt_get_monotonic() + interval */
-
-Inline qtime_mono_t /* monotonic time from CLOCK_REALTIME */
-qt_realtime2monotonic(qtime_real_t realtime) ;
-Inline qtime_real_t /* CLOCK_REALTIME from monotonic time */
-qt_monotonic2realtime(qtime_mono_t monotonic) ;
-
-/* Function to manufacture a monotonic clock. */
-extern qtime_mono_t
-qt_craft_monotonic(void) ;
+Inline qtime_mono_t qt_add_monotonic(qtime_t interval) ;
+ /* qt_get_monotonic() + interval */
/* These are provided just in case gettimeofday() != CLOCK_REALTIME */
-Inline qtime_tod_t
-qt_get_timeofday(void) ; /* gettimeofday(&tv, NULL) */
+Inline qtime_tod_t qt_get_timeofday(void) ;
+ /* gettimeofday(&tv, NULL) */
+Inline qtime_tod_t qt_add_timeofday(qtime_t interval) ;
+ /* qt_get_timeofday() + interval */
-Inline qtime_tod_t
-qt_add_timeofday(qtime_t interval) ; /* qt_get_timeofday() + interval */
-
-Inline qtime_mono_t /* monotonic time from timeofday */
-qt_timeofday2monotonic(qtime_tod_t timeofday) ;
-Inline qtime_tod_t /* timeofday from monotonic time */
-qt_monotonic2timeofday(qtime_mono_t monotonic) ;
+/*==============================================================================
+ * Primitive random number generation.
+ *
+ * Uses time and other stuff to produce something which is not particularly
+ * predictable.
+ */
+extern uint32_t qt_random(uint32_t seed) ;
/*==============================================================================
* Inline conversion functions
*/
-/* Convert timespec to qtime_t
+/*------------------------------------------------------------------------------
+ * Convert timespec to qtime_t
*
* Returns qtime_t value.
*/
@@ -141,7 +127,8 @@ timespec2qtime(struct timespec* p_ts)
confirm(QTIME_SECOND == TIMESPEC_SECOND) ;
} ;
-/* Convert timeval to qtime_t
+/*------------------------------------------------------------------------------
+ * Convert timeval to qtime_t
*
* Returns qtime_t value.
*/
@@ -152,7 +139,8 @@ timeval2qtime(struct timeval* p_tv)
confirm(QTIME_SECOND == TIMEVAL_SECOND * 1000) ;
} ;
-/* Convert qtime_t to timespec
+/*------------------------------------------------------------------------------
+ * Convert qtime_t to timespec
*
* Takes address of struct timespec and returns that address.
*/
@@ -169,7 +157,8 @@ qtime2timespec(struct timespec* p_ts, qtime_t qt)
return p_ts ;
} ;
-/* Convert timespec to qtime_t
+/*------------------------------------------------------------------------------
+ * Convert timespec to qtime_t
*
* Takes address of struct timespec and returns that address.
*/
@@ -190,7 +179,11 @@ qtime2timeval(struct timeval* p_tv, qtime_t qt)
* Inline Clock Functions.
*/
-/* Read given clock & return a qtime_t value.
+/* Function to manufacture a monotonic clock. */
+Private qtime_mono_t qt_craft_monotonic(void) ;
+
+/*------------------------------------------------------------------------------
+ * Read given clock & return a qtime_t value.
*
* While possibility of error is essentially theoretical, must treat it as a
* FATAL error -- cannot continue with broken time value !
@@ -207,7 +200,8 @@ qt_clock_gettime(clockid_t clock_id)
return timespec2qtime(&ts) ;
} ;
-/* clock_gettime(CLOCK_REALTIME, ...) -- returning qtime_t value
+/*------------------------------------------------------------------------------
+ * clock_gettime(CLOCK_REALTIME, ...) -- returning qtime_t value
*
* While possibility of error is essentially theoretical, must treat it as a
* FATAL error -- cannot continue with broken time value !
@@ -218,7 +212,8 @@ qt_get_realtime(void)
return qt_clock_gettime(CLOCK_REALTIME) ;
} ;
-/* qt_get_realtime() + interval
+/*------------------------------------------------------------------------------
+ * qt_get_realtime() + interval
*/
Inline qtime_real_t
qt_add_realtime(qtime_t interval)
@@ -226,7 +221,8 @@ qt_add_realtime(qtime_t interval)
return qt_get_realtime() + interval;
} ;
-/* clock_gettime(CLOCK_MONOTONIC, ...) OR qt_craft_monotonic()
+/*------------------------------------------------------------------------------
+ * clock_gettime(CLOCK_MONOTONIC, ...) OR qt_craft_monotonic()
* -- returning qtime_t value
*
* While possibility of error is essentially theoretical, must treat it as a
@@ -242,7 +238,8 @@ qt_get_monotonic(void)
#endif
} ;
-/* qt_get_monotonic() + interval
+/*------------------------------------------------------------------------------
+ * qt_get_monotonic() + interval
*/
Inline qtime_mono_t
qt_add_monotonic(qtime_t interval)
@@ -250,7 +247,8 @@ qt_add_monotonic(qtime_t interval)
return qt_get_monotonic() + interval;
} ;
-/* gettimeofday(&tv, NULL) -- returning qtime_t value
+/*------------------------------------------------------------------------------
+ * gettimeofday(&tv, NULL) -- returning qtime_t value
*/
Inline qtime_tod_t
qt_get_timeofday(void)
@@ -260,7 +258,8 @@ qt_get_timeofday(void)
return timeval2qtime(&tv) ;
}
-/* qt_get_timeofday() + interval
+/*------------------------------------------------------------------------------
+ * qt_get_timeofday() + interval
*/
Inline qtime_tod_t
qt_add_timeofday(qtime_t interval)
@@ -268,36 +267,4 @@ qt_add_timeofday(qtime_t interval)
return qt_get_timeofday() + interval;
} ;
-/*==============================================================================
- * Conversion between realtime/timeofday and monotonic
- */
-
-/* Convert a CLOCK_REALTIME time to our local monotonic time. */
-Inline qtime_mono_t
-qt_realtime2monotonic(qtime_real_t realtime)
-{
- return qt_get_monotonic() + (realtime - qt_get_realtime()) ;
-} ;
-
-/* Convert a local monotonic time to CLOCK_REALTIME time. */
-Inline qtime_real_t
-qt_monotonic2realtime(qtime_mono_t monotonic)
-{
- return qt_get_realtime() + (monotonic - qt_get_monotonic()) ;
-} ;
-
-/* Convert a gettimeofday() time to our local monotonic time. */
-Inline qtime_mono_t
-qt_timeofday2monotonic(qtime_tod_t timeofday)
-{
- return qt_get_monotonic() + (timeofday - qt_get_timeofday()) ;
-} ;
-
-/* Convert a local monotonic time to gettimeofday() time. */
-Inline qtime_tod_t
-qt_monotonic2timeofday(qtime_mono_t monotonic)
-{
- return qt_get_timeofday() + (monotonic - qt_get_monotonic()) ;
-} ;
-
#endif /* _ZEBRA_QTIME_H */