diff options
author | Chris Hall (GMCH) <chris.hall@highwayman.com> | 2009-12-09 17:59:03 +0000 |
---|---|---|
committer | Chris Hall (GMCH) <chris.hall@highwayman.com> | 2009-12-09 17:59:03 +0000 |
commit | b3edb8b2b5d1e9c7b23bad9de6802e89c3a8fd0b (patch) | |
tree | 8f71c2d4efb98e8644c881c3d055ebf29b6ddb4c /lib/qpselect.c | |
parent | 482674bb1e9401fa4f954fb03cdc84ad9908845f (diff) | |
download | quagga-b3edb8b2b5d1e9c7b23bad9de6802e89c3a8fd0b.tar.bz2 quagga-b3edb8b2b5d1e9c7b23bad9de6802e89c3a8fd0b.tar.xz |
Ensure all timeouts are timeout times in qtime_mono_t.
Introduced separate types for qtime_mono_t and qtime_real_t, to
distinguish the time base of a given value.
Revised all users of timeouts so that they are all expressed as
qtime_mono_t values, so are all Quagga monotonic time based.
Revised qpt_cond_timedwait() so that all condition variables use the
same timebase (CLOCK_MONOTONIC if available, by default). Now all
timeout times are qtime_mono_t, and are converted to whatever the
condition variable is set to, if necessary.
Added explicit timeout to mqueue.
Fixed qps_pselect() to zeroise result vectors if no fds are
reported pending -- seems the O/S does not do this.
Diffstat (limited to 'lib/qpselect.c')
-rw-r--r-- | lib/qpselect.c | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/lib/qpselect.c b/lib/qpselect.c index 9f5417d0..44ab5e56 100644 --- a/lib/qpselect.c +++ b/lib/qpselect.c @@ -53,7 +53,10 @@ * may then be enabled/disabled for any combination of error/read/write * "mode" events. * - * * a timeout + * * a timeout *time* + * + * This is a qtime monotonic time at which to time out. (This is unlike + * pselect() itself, which takes a timeout interval.) * * Infinite timeouts are not supported. * @@ -275,7 +278,7 @@ qps_set_signal(qps_selection qps, int signum, sigset_t sigmask) * * There is no support for an infinite timeout. * - * Returns: -1 => EINTR occurred + * Returns: -1 => EINTR occurred -- ie a signal has gone off * 0 => hit timeout -- no files are ready * > 0 => there are this many files ready in one or more modes * @@ -284,7 +287,7 @@ qps_set_signal(qps_selection qps, int signum, sigset_t sigmask) * The qps_dispatch_next() processes the returns from pselect(). */ int -qps_pselect(qps_selection qps, qtime_t timeout) +qps_pselect(qps_selection qps, qtime_mono_t timeout) { struct timespec ts ; qps_mnum_t mnum ; @@ -301,7 +304,7 @@ qps_pselect(qps_selection qps, qtime_t timeout) /* given count of fds -- but it does no harm to be tidy, and should */ /* not have to do this often.) */ if (qps->pend_count != 0) - qps_super_set_zero(qps->enabled, qps_mnum_count) ; + qps_super_set_zero(qps->enabled, qps_mnum_count) ; /* Prepare the argument/result bitmaps */ /* Capture pend_mnum and tried_count[] */ @@ -336,13 +339,21 @@ qps_pselect(qps_selection qps, qtime_t timeout) qtime2timespec(&ts, timeout), (qps->signum != 0) ? &qps->sigmask : NULL) ; - qps->pend_count = (n >= 0) ? n : 0 ; /* avoid setting -ve pend_count */ + /* If have something, set and return the pending count. */ + if (n > 0) + { + assert(qps->pend_mnum < qps_mnum_count) ; /* expected something */ + + return qps->pend_count = n ; /* set and return pending count */ + } ; + + /* Flush the results vectors -- not apparently done if n <= 0) */ + qps_super_set_zero(qps->enabled, qps_mnum_count) ; - /* if 1 or more pending results, then must have at least one pending mode */ - assert((n <= 0) || (qps->pend_mnum < qps_mnum_count)) ; + qps->pend_count = 0 ; /* nothing pending */ - /* Return appropriately, if we can */ - if ((n >= 0) || (errno == EINTR)) + /* Return appropriately, if we can */ + if ((n == 0) || (errno == EINTR)) return n ; zabort_errno("Failed in pselect") ; |