timer.c revision b0f24684b34fd81bc40d5794586dd30dc32dfdd4
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt * We use macros instead of calling the os_ routines directly because
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt * the capital letters make the locking stand out.
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt * We INSIST that they succeed since there's no way for us to continue
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt * if they fail.
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt#define BROADCAST(cvp) INSIST(os_condition_broadcast((cvp)))
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt#define WAIT(cvp, lp) INSIST(os_condition_wait((cvp), (lp)))
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt#define WAITUNTIL(cvp, lp, tp, bp) INSIST(os_condition_waituntil((cvp), \
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt /* Not locked. */
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt unsigned int magic;
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt /* Locked by timer lock. */
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt unsigned int references;
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt /* Locked by manager lock. */
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt unsigned int index;
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt#define TIMER_MANAGER_MAGIC 0x54494D4DU /* TIMM. */
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt /* Not locked. */
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt unsigned int magic;
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt /* Locked by manager lock. */
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt unsigned int nscheduled;
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt if (os_time_compare(&t1->next_time, &t2->next_time) < 0)
351b62535d4c4f89883bfdba025999dd32490266Evan Huntstatic inline void
351b62535d4c4f89883bfdba025999dd32490266Evan Huntnexttime(timer_t timer, os_time_t *nowp, boolean_t first_time) {
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt * The caller must ensure locking.
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt os_time_add(nowp, &timer->interval, &timer->next_time);
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt /* Idle timer. */
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt if (os_time_compare(&timer->touched, nowp) <= 0) {
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt if (os_time_compare(&idle, &timer->interval) >= 0) {
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt * Time touched is in the future! Make it now.
static inline isc_result
return (ISC_R_NOMEMORY);
return (ISC_R_SUCCESS);
if (need_wakeup)
return (ISC_R_UNEXPECTED);
return (ISC_R_NOMEMORY);
return (ISC_R_UNEXPECTED);
return (result);
return (ISC_R_UNEXPECTED);
return (result);
return (ISC_R_SUCCESS);
return (ISC_R_UNEXPECTED);
return (ISC_R_SUCCESS);
if (free_timer)
ts.tv_sec = manager->next_time.seconds;
ts.tv_nsec = manager->next_time.nanoseconds;
&timeout);
return (NULL);
return (ISC_R_NOMEMORY);
return (ISC_R_NOMEMORY);
return (ISC_R_UNEXPECTED);
return (ISC_R_UNEXPECTED);
return (ISC_R_UNEXPECTED);
return (ISC_R_SUCCESS);