From: Michal Bloch Date: Tue, 29 Jun 2021 18:17:54 +0000 (+0200) Subject: Minor improvements to the udev polling loop. X-Git-Tag: submit/tizen/20210705.023617~5 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F08%2F260608%2F2;p=platform%2Fcore%2Fapi%2Fperipheral-io.git Minor improvements to the udev polling loop. Change-Id: I068e2cbfe0243221f879961bb19ae8ea5e9b65f3 --- diff --git a/src/common.c b/src/common.c index 969b39a..ed56e67 100644 --- a/src/common.c +++ b/src/common.c @@ -7,6 +7,7 @@ #include #define UDEV_MONITOR_POLL_TIMEOUT_MILISECONDS 100 +#define UDEV_MONITOR_POLL_ITERATIONS 10 //! How many times to poll? Affects the total timeout. int peripheral_lock(const char *file_name) { @@ -95,13 +96,17 @@ int peripheral_wait_for_udev(struct udev_monitor *monitor, UdevCompareFunc func, pfd.fd = udev_monitor_get_fd(monitor); pfd.events = POLLIN; - for (int cnt = 0; cnt < 10; cnt++) { - _D("poll iteration"); - if (poll(&pfd, 1, UDEV_MONITOR_POLL_TIMEOUT_MILISECONDS) < 0) { - _E("Failed to watch udev monitor"); + for (int cnt = 0; cnt < UDEV_MONITOR_POLL_ITERATIONS; cnt++) { + _D("poll iteration %d", cnt); + int ready = poll(&pfd, 1, UDEV_MONITOR_POLL_TIMEOUT_MILISECONDS); + if (ready < 0) { + _E("Failed to watch udev monitor %m"); return -EIO; } + if (ready == 0) + continue; + struct udev_device *dev = udev_monitor_receive_device(monitor); if (dev) { if (func(dev, func_data)) {