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 <jb...@redhat.com>
---
 clock.c |   12 +++++++++++-
 1 files changed, 11 insertions(+), 1 deletions(-)

diff --git a/clock.c b/clock.c
index 99b4b49d418c..f70e87bb7239 100644
--- a/clock.c
+++ b/clock.c
@@ -85,6 +85,7 @@ struct clock {
        LIST_HEAD(ports_head, port) ports;
        struct port *uds_port;
        struct pollfd *pollfd;
+       int pollfd_valid;
        int nports; /* does not include the UDS port */
        int free_running;
        int freq_est_interval;
@@ -1000,16 +1001,24 @@ static void clock_fill_pollfd(struct pollfd *dest, 
struct port *p)
        dest[i].events = POLLIN|POLLPRI;
 }
 
-void clock_fda_changed(struct clock *c)
+static void clock_check_pollfd(struct clock *c)
 {
        struct port *p;
        struct pollfd *dest = c->pollfd;
 
+       if (c->pollfd_valid)
+               return;
        LIST_FOREACH(p, &c->ports, list) {
                clock_fill_pollfd(dest, p);
                dest += N_CLOCK_PFD;
        }
        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,
@@ -1210,6 +1219,7 @@ int clock_poll(struct clock *c)
        struct pollfd *cur;
        struct port *p;
 
+       clock_check_pollfd(c);
        cnt = poll(c->pollfd, (c->nports + 1) * N_CLOCK_PFD, -1);
        if (cnt < 0) {
                if (EINTR == errno) {
-- 
1.7.6.5


------------------------------------------------------------------------------
Open source business process management suite built on Java and Eclipse
Turn processes into business applications with Bonita BPM Community Edition
Quickly connect people, data, and systems into organized workflows
Winner of BOSSIE, CODIE, OW2 and Gartner awards
http://p.sf.net/sfu/Bonitasoft
_______________________________________________
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel

Reply via email to