Commit 94d45b3c authored by Alessandro Rubini's avatar Alessandro Rubini

timeout: lift the requirement for the value to not be zero

We don't zero timer any more (see preceding commit), no need
to special case anything.
Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent c5de0748
......@@ -197,7 +197,6 @@ struct pp_time_operations {
int (*adjust_offset)(struct pp_instance *ppi, long offset_ns);
int (*adjust_freq)(struct pp_instance *ppi, long freq_ppb);
int (*init_servo)(struct pp_instance *ppi);
/* calc_timeout cannot return zero */
unsigned long (*calc_timeout)(struct pp_instance *ppi, int millisec);
};
......
......@@ -92,15 +92,11 @@ static unsigned long bare_calc_timeout(struct pp_instance *ppi, int millisec)
{
struct bare_timespec now;
uint64_t now_ms;
unsigned long result;
if (!millisec)
millisec = 1;
sys_clock_gettime(CLOCK_MONOTONIC, &now);
now_ms = 1000LL * now.tv_sec + now.tv_nsec / 1000 / 1000;
result = now_ms + millisec;
return result ? result : 1; /* cannot return 0 */
return now_ms + millisec;
}
struct pp_time_operations bare_time_ops = {
......
......@@ -110,10 +110,7 @@ static inline int sim_init_servo(struct pp_instance *ppi)
static unsigned long sim_calc_timeout(struct pp_instance *ppi, int millisec)
{
unsigned long res;
res = millisec + SIM_PPI_ARCH(ppi)->time.current_ns / 1000LL / 1000LL;
return res ? res : 1;
return millisec + SIM_PPI_ARCH(ppi)->time.current_ns / 1000LL / 1000LL;
}
struct pp_time_operations sim_time_ops = {
......
......@@ -117,15 +117,11 @@ static unsigned long unix_calc_timeout(struct pp_instance *ppi, int millisec)
{
struct timespec now;
uint64_t now_ms;
unsigned long result;
if (!millisec)
millisec = 1;
clock_gettime(CLOCK_MONOTONIC, &now);
now_ms = 1000LL * now.tv_sec + now.tv_nsec / 1000 / 1000;
result = now_ms + millisec;
return result ? result : 1; /* cannot return 0 */
return now_ms + millisec;
}
struct pp_time_operations unix_time_ops = {
......
......@@ -61,10 +61,7 @@ static int wrpc_time_adjust(struct pp_instance *ppi, long offset_ns,
static unsigned long wrpc_calc_timeout(struct pp_instance *ppi, int millisec)
{
unsigned long now_ms = timer_get_tics();
now_ms += millisec;
return now_ms ? now_ms : 1; /* cannot return 0 */
return timer_get_tics() + millisec;
}
struct pp_time_operations wrpc_time_ops = {
......
......@@ -105,8 +105,7 @@ void pp_timeout_setall(struct pp_instance *ppi)
int pp_timeout(struct pp_instance *ppi, int index)
{
int ret = ppi->timeouts[index] &&
time_after_eq(ppi->t_ops->calc_timeout(ppi, 0),
int ret = time_after_eq(ppi->t_ops->calc_timeout(ppi, 0),
ppi->timeouts[index]);
if (ret)
......@@ -119,9 +118,6 @@ int pp_ms_to_timeout(struct pp_instance *ppi, int index)
{
signed long ret;
if (!ppi->timeouts[index]) /* not pending, nothing to wait for */
return 0;
ret = ppi->timeouts[index] - ppi->t_ops->calc_timeout(ppi, 0);
return ret <= 0 ? 0 : ret;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment