Lazy regeneration of pollfd

There's no need to regenerate pollfd multiple times during batches of port
operations (like creating of the clock). Just be lazy and regenerate it only
once it's needed.

Signed-off-by: Jiri Benc <jbenc@redhat.com>
master
Jiri Benc 2014-08-14 15:56:04 +02:00 committed by Richard Cochran
parent 08575133b3
commit 83f637fb8e
1 changed files with 11 additions and 1 deletions

12
clock.c
View File

@ -85,6 +85,7 @@ struct clock {
LIST_HEAD(ports_head, port) ports; LIST_HEAD(ports_head, port) ports;
struct port *uds_port; struct port *uds_port;
struct pollfd *pollfd; struct pollfd *pollfd;
int pollfd_valid;
int nports; /* does not include the UDS port */ int nports; /* does not include the UDS port */
int free_running; int free_running;
int freq_est_interval; int freq_est_interval;
@ -1002,16 +1003,24 @@ static void clock_fill_pollfd(struct pollfd *dest, struct port *p)
dest[i].events = POLLIN|POLLPRI; dest[i].events = POLLIN|POLLPRI;
} }
void clock_fda_changed(struct clock *c) static void clock_check_pollfd(struct clock *c)
{ {
struct port *p; struct port *p;
struct pollfd *dest = c->pollfd; struct pollfd *dest = c->pollfd;
if (c->pollfd_valid)
return;
LIST_FOREACH(p, &c->ports, list) { LIST_FOREACH(p, &c->ports, list) {
clock_fill_pollfd(dest, p); clock_fill_pollfd(dest, p);
dest += N_CLOCK_PFD; dest += N_CLOCK_PFD;
} }
clock_fill_pollfd(dest, c->uds_port); clock_fill_pollfd(dest, c->uds_port);
c->pollfd_valid = 1;
}
void clock_fda_changed(struct clock *c)
{
c->pollfd_valid = 0;
} }
static int clock_do_forward_mgmt(struct clock *c, static int clock_do_forward_mgmt(struct clock *c,
@ -1212,6 +1221,7 @@ int clock_poll(struct clock *c)
struct pollfd *cur; struct pollfd *cur;
struct port *p; struct port *p;
clock_check_pollfd(c);
cnt = poll(c->pollfd, (c->nports + 1) * N_CLOCK_PFD, -1); cnt = poll(c->pollfd, (c->nports + 1) * N_CLOCK_PFD, -1);
if (cnt < 0) { if (cnt < 0) {
if (EINTR == errno) { if (EINTR == errno) {