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/qpthreads.h | |
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/qpthreads.h')
-rw-r--r-- | lib/qpthreads.h | 65 |
1 files changed, 12 insertions, 53 deletions
diff --git a/lib/qpthreads.h b/lib/qpthreads.h index 1c51a9ee..5a442cc7 100644 --- a/lib/qpthreads.h +++ b/lib/qpthreads.h @@ -170,7 +170,7 @@ qpt_mutex_unlock(qpt_mutex_t* mx) ; /* do nothing if mx == NULL */ /*============================================================================== * Condition Variable handling * - * Quagga's default clock for condition variables is QPT_COND_CLOCK_ID, which + * Quagga's clock for condition variables is QPT_COND_CLOCK_ID, which * may be set elsewhere. If it is not set then it is set here to be: * * * CLOCK_MONOTONIC if available @@ -179,30 +179,30 @@ qpt_mutex_unlock(qpt_mutex_t* mx) ; /* do nothing if mx == NULL */ * QPT_COND_CLOCK_MONOTONIC is set if CLOCK_MONOTONIC is used (and must be set * if QPT_COND_CLOCK_ID is set elsewhere to something that is monotonic). * - * NB: qpt_cond_get_timeout_time uses QPT_COND_CLOCK_ID. + * NB: the time-out time passed to qpt_cond_timedwait() is a qtime_mono_t + * time (so based on qtime's monotonic time, which is CLOCK_MONOTONIC if + * that is available. * - * If a specific clock is required, it can be set... but the user of the - * condition variable must take care to base time-out times on that clock. + * Otherwise, there is a conversion step from qtime_mono_t to whatever the + * timebase for the condition variable is. * * NB: static initialisation of condition variables is not supported, to avoid * confusion between the standard default and Quagga's default. */ #ifndef QPT_COND_CLOCK_ID -# ifndef HAVE_CLOCK_MONOTONIC -# define QPT_COND_CLOCK_ID CLOCK_REALTIME -# undef QPT_COND_CLOCK_MONOTONIC -# else +# ifdef HAVE_CLOCK_MONOTONIC # define QPT_COND_CLOCK_ID CLOCK_MONOTONIC # define QPT_COND_CLOCK_MONOTONIC 1 +# else +# define QPT_COND_CLOCK_ID CLOCK_REALTIME +# undef QPT_COND_CLOCK_MONOTONIC # endif #endif enum qpt_cond_options { qpt_cond_quagga = 0x0000, /* Quagga's default */ - qpt_cond_realtime = 0x0001, /* standard default */ - qpt_cond_monotonic = 0x0002, } ; extern qpt_cond_t* @@ -217,11 +217,8 @@ qpt_cond_destroy(qpt_cond_t* cv, int free_cond) ; Inline void qpt_cond_wait(qpt_cond_t* cv, qpt_mutex_t* mx) ; -Inline qtime_t -qpt_cond_get_timeout_time(qtime_t wait) ; - -Inline int -qpt_cond_timedwait(qpt_cond_t* cv, qpt_mutex_t* mx, qtime_t tot) ; +extern int +qpt_cond_timedwait(qpt_cond_t* cv, qpt_mutex_t* mx, qtime_mono_t timeout_time) ; Inline void qpt_cond_signal(qpt_cond_t* cv) ; @@ -319,44 +316,6 @@ qpt_cond_wait(qpt_cond_t* cv, qpt_mutex_t* mx) #endif } ; -/* Get a time-out time (for use with qpt_cond_timedwait). - * - * Returns the current system time plus the given wait time. - */ - -Inline qtime_t -qpt_cond_get_timeout_time(qtime_t wait) -{ - return qt_clock_gettime(QPT_COND_CLOCK_ID) + wait ; -} ; - -/* Wait for given condition variable or time-out. - * - * Returns: wait succeeded (1 => success, 0 => timed-out). - * - * The time-out is an *absolute* time expressed as a qtime_t. - * - * NB: qpt_cond_get_timeout_time() should be used to generate the required - * time-out. That uses CLOCK_ - * - * Has to check the return value, so zabort_errno if not EBUSY. - */ - -Inline int -qpt_cond_timedwait(qpt_cond_t* cv, qpt_mutex_t* mx, qtime_t tot) -{ - struct timespec ts ; - - int err = pthread_cond_timedwait(cv, mx, qtime2timespec(&ts, tot)) ; - if (err == 0) - return 1 ; /* got condition */ - if (err == ETIMEDOUT) - return 0 ; /* got time-out */ - - zabort_err("pthread_cond_timedwait failed", err) ; - /* crunch */ -} ; - /* Signal given condition. * * Unless both NCHECK_QPTHREADS and NDEBUG are defined, checks that the |