Skip to content

Commit

Permalink
Rename set_tmo() to set_tmo_log(), add set_tmo_lin()
Browse files Browse the repository at this point in the history
Signed-off-by: Delio Brignoli <[email protected]>
  • Loading branch information
dbrignoli authored and richardcochran committed Mar 20, 2013
1 parent d374ad6 commit 455ebe7
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
2 changes: 1 addition & 1 deletion clock.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ static int clock_fault_timeout(struct clock *c, int index, int set)
} else {
pr_debug("clearing fault on port %d", index);
}
return set_tmo(c->fault_fd[index], scale, log_seconds);
return set_tmo_log(c->fault_fd[index], scale, log_seconds);
}

static void clock_freq_est_reset(struct clock *c)
Expand Down
22 changes: 16 additions & 6 deletions port.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ static int source_pid_eq(struct ptp_message *m1, struct ptp_message *m2)
&m2->header.sourcePortIdentity);
}

int set_tmo(int fd, unsigned int scale, int log_seconds)
int set_tmo_log(int fd, unsigned int scale, int log_seconds)
{
struct itimerspec tmo = {
{0, 0}, {0, 0}
Expand All @@ -187,6 +187,16 @@ int set_tmo(int fd, unsigned int scale, int log_seconds)
return timerfd_settime(fd, 0, &tmo, NULL);
}

int set_tmo_lin(int fd, int seconds)
{
struct itimerspec tmo = {
{0, 0}, {0, 0}
};

tmo.it_value.tv_sec = seconds;
return timerfd_settime(fd, 0, &tmo, NULL);
}

static void fc_clear(struct foreign_clock *fc)
{
struct ptp_message *m;
Expand Down Expand Up @@ -720,7 +730,7 @@ static void port_nrate_initialize(struct port *p)

static int port_set_announce_tmo(struct port *p)
{
return set_tmo(p->fda.fd[FD_ANNOUNCE_TIMER],
return set_tmo_log(p->fda.fd[FD_ANNOUNCE_TIMER],
p->announceReceiptTimeout, p->logAnnounceInterval);
}

Expand All @@ -731,7 +741,7 @@ static int port_set_delay_tmo(struct port *p)
};
int index;
if (p->delayMechanism == DM_P2P) {
return set_tmo(p->fda.fd[FD_DELAY_TIMER], 1,
return set_tmo_log(p->fda.fd[FD_DELAY_TIMER], 1,
p->logMinPdelayReqInterval);
}
index = random() % TMTAB_MAX;
Expand All @@ -741,18 +751,18 @@ static int port_set_delay_tmo(struct port *p)

static int port_set_manno_tmo(struct port *p)
{
return set_tmo(p->fda.fd[FD_MANNO_TIMER], 1, p->logAnnounceInterval);
return set_tmo_log(p->fda.fd[FD_MANNO_TIMER], 1, p->logAnnounceInterval);
}

static int port_set_qualification_tmo(struct port *p)
{
return set_tmo(p->fda.fd[FD_QUALIFICATION_TIMER],
return set_tmo_log(p->fda.fd[FD_QUALIFICATION_TIMER],
1+clock_steps_removed(p->clock), p->logAnnounceInterval);
}

static int port_set_sync_tmo(struct port *p)
{
return set_tmo(p->fda.fd[FD_SYNC_TIMER], 1, p->logSyncInterval);
return set_tmo_log(p->fda.fd[FD_SYNC_TIMER], 1, p->logSyncInterval);
}

static void port_show_transition(struct port *p,
Expand Down
15 changes: 14 additions & 1 deletion port.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,19 @@ enum port_state port_state(struct port *port);
* @param log_seconds The exponential factor for the timer.
* @return Zero on success, non-zero otherwise.
*/
int set_tmo(int fd, unsigned int scale, int log_seconds);
int set_tmo_log(int fd, unsigned int scale, int log_seconds);

/**
* Utility function for setting or resetting a file descriptor timer.
*
* This function sets the timer 'fd' to the value of the 'seconds' parameter.
*
* Passing 'seconds' as zero disables the timer.
*
* @param fd A file descriptor previously opened with timerfd_create(2).
* @param seconds The timeout value for the timer.
* @return Zero on success, non-zero otherwise.
*/
int set_tmo_lin(int fd, int seconds);

#endif

0 comments on commit 455ebe7

Please sign in to comment.