summaryrefslogtreecommitdiff
path: root/lib/thread.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/thread.c')
-rw-r--r--lib/thread.c141
1 files changed, 16 insertions, 125 deletions
diff --git a/lib/thread.c b/lib/thread.c
index 8d75509b1d..a128786c3d 100644
--- a/lib/thread.c
+++ b/lib/thread.c
@@ -32,15 +32,6 @@
#include "command.h"
#include "sigevent.h"
-#if defined HAVE_SNMP && defined SNMP_AGENTX
-#include <net-snmp/net-snmp-config.h>
-#include <net-snmp/net-snmp-includes.h>
-#include <net-snmp/agent/net-snmp-agent-includes.h>
-#include <net-snmp/agent/snmp_vars.h>
-
-extern int agentx_enabled;
-#endif
-
#if defined(__APPLE__)
#include <mach/mach.h>
#include <mach/mach_time.h>
@@ -48,12 +39,8 @@ extern int agentx_enabled;
/* Recent absolute time of day */
struct timeval recent_time;
-static struct timeval last_recent_time;
/* Relative time, since startup */
static struct timeval relative_time;
-static struct timeval relative_time_base;
-/* init flag */
-static unsigned short timers_inited;
static struct hash *cpu_record = NULL;
@@ -106,27 +93,6 @@ timeval_elapsed (struct timeval a, struct timeval b)
+ (a.tv_usec - b.tv_usec));
}
-#if !defined(HAVE_CLOCK_MONOTONIC) && !defined(__APPLE__)
-static void
-quagga_gettimeofday_relative_adjust (void)
-{
- struct timeval diff;
- if (timeval_cmp (recent_time, last_recent_time) < 0)
- {
- relative_time.tv_sec++;
- relative_time.tv_usec = 0;
- }
- else
- {
- diff = timeval_subtract (recent_time, last_recent_time);
- relative_time.tv_sec += diff.tv_sec;
- relative_time.tv_usec += diff.tv_usec;
- relative_time = timeval_adjust (relative_time);
- }
- last_recent_time = recent_time;
-}
-#endif /* !HAVE_CLOCK_MONOTONIC && !__APPLE__ */
-
/* gettimeofday wrapper, to keep recent_time updated */
static int
quagga_gettimeofday (struct timeval *tv)
@@ -137,12 +103,6 @@ quagga_gettimeofday (struct timeval *tv)
if (!(ret = gettimeofday (&recent_time, NULL)))
{
- /* init... */
- if (!timers_inited)
- {
- relative_time_base = last_recent_time = recent_time;
- timers_inited = 1;
- }
/* avoid copy if user passed recent_time pointer.. */
if (tv != &recent_time)
*tv = recent_time;
@@ -182,8 +142,7 @@ quagga_get_relative (struct timeval *tv)
return 0;
}
#else /* !HAVE_CLOCK_MONOTONIC && !__APPLE__ */
- if (!(ret = quagga_gettimeofday (&recent_time)))
- quagga_gettimeofday_relative_adjust();
+#error no monotonic clock on this system
#endif /* HAVE_CLOCK_MONOTONIC */
if (tv)
@@ -192,18 +151,6 @@ quagga_get_relative (struct timeval *tv)
return ret;
}
-/* Get absolute time stamp, but in terms of the internal timer
- * Could be wrong, but at least won't go back.
- */
-static void
-quagga_real_stabilised (struct timeval *tv)
-{
- *tv = relative_time_base;
- tv->tv_sec += relative_time.tv_sec;
- tv->tv_usec += relative_time.tv_usec;
- *tv = timeval_adjust (*tv);
-}
-
/* Exported Quagga timestamp function.
* Modelled on POSIX clock_gettime.
*/
@@ -212,29 +159,19 @@ quagga_gettime (enum quagga_clkid clkid, struct timeval *tv)
{
switch (clkid)
{
- case QUAGGA_CLK_REALTIME:
- return quagga_gettimeofday (tv);
case QUAGGA_CLK_MONOTONIC:
return quagga_get_relative (tv);
- case QUAGGA_CLK_REALTIME_STABILISED:
- quagga_real_stabilised (tv);
- return 0;
default:
errno = EINVAL;
return -1;
}
}
-/* time_t value in terms of stabilised absolute time.
- * replacement for POSIX time()
- */
time_t
-quagga_time (time_t *t)
+quagga_monotime (void)
{
struct timeval tv;
- quagga_real_stabilised (&tv);
- if (t)
- *t = tv.tv_sec;
+ quagga_get_relative(&tv);
return tv.tv_sec;
}
@@ -983,6 +920,17 @@ funcname_thread_add_timer_msec (struct thread_master *m,
arg, &trel, debugargpass);
}
+/* Add timer event thread with "millisecond" resolution */
+struct thread *
+funcname_thread_add_timer_tv (struct thread_master *m,
+ int (*func) (struct thread *),
+ void *arg, struct timeval *tv,
+ debugargdef)
+{
+ return funcname_thread_add_timer_timeval (m, func, THREAD_TIMER,
+ arg, tv, debugargpass);
+}
+
/* Add a background thread, with an optional millisec delay */
struct thread *
funcname_thread_add_background (struct thread_master *m,
@@ -1343,12 +1291,7 @@ thread_fetch (struct thread_master *m, struct thread *fetch)
while (1)
{
int num = 0;
-#if defined HAVE_SNMP && defined SNMP_AGENTX
- struct timeval snmp_timer_wait;
- int snmpblock = 0;
- int fdsetsize;
-#endif
-
+
/* Signals pre-empt everything */
quagga_sigevent_process ();
@@ -1384,35 +1327,7 @@ thread_fetch (struct thread_master *m, struct thread *fetch)
(!timer_wait || (timeval_cmp (*timer_wait, *timer_wait_bg) > 0)))
timer_wait = timer_wait_bg;
}
-
-#if defined HAVE_SNMP && defined SNMP_AGENTX
- /* When SNMP is enabled, we may have to select() on additional
- FD. snmp_select_info() will add them to `readfd'. The trick
- with this function is its last argument. We need to set it to
- 0 if timer_wait is not NULL and we need to use the provided
- new timer only if it is still set to 0. */
- if (agentx_enabled)
- {
- fdsetsize = FD_SETSIZE;
- snmpblock = 1;
- if (timer_wait)
- {
- snmpblock = 0;
- memcpy(&snmp_timer_wait, timer_wait, sizeof(struct timeval));
- }
-#if defined(HAVE_POLL)
- /* clear fdset since there are no other fds in fd_set,
- then add injected fds from snmp_select_info into pollset */
- FD_ZERO(&readfd);
-#endif
- snmp_select_info(&fdsetsize, &readfd, &snmp_timer_wait, &snmpblock);
-#if defined(HAVE_POLL)
- add_snmp_pollfds(m, &readfd, fdsetsize);
-#endif
- if (snmpblock == 0)
- timer_wait = &snmp_timer_wait;
- }
-#endif
+
num = fd_select (m, FD_SETSIZE, &readfd, &writefd, &exceptfd, timer_wait);
/* Signals should get quick treatment */
@@ -1424,30 +1339,6 @@ thread_fetch (struct thread_master *m, struct thread *fetch)
return NULL;
}
-#if defined HAVE_SNMP && defined SNMP_AGENTX
-#if defined(HAVE_POLL)
- /* re-enter pollfds in fd_set for handling in snmp_read */
- FD_ZERO(&readfd);
- nfds_t i;
- for (i = m->handler.pfdcount; i < m->handler.pfdcountsnmp; ++i)
- {
- if (m->handler.pfds[i].revents == POLLIN)
- FD_SET(m->handler.pfds[i].fd, &readfd);
- }
-#endif
- if (agentx_enabled)
- {
- if (num > 0)
- snmp_read(&readfd);
- else if (num == 0)
- {
- snmp_timeout();
- run_alarms();
- }
- netsnmp_check_outstanding_agent_requests();
- }
-#endif
-
/* Check foreground timers. Historically, they have had higher
priority than I/O threads, so let's push them onto the ready
list in front of the I/O threads. */