name magic numbers in poll() calls 21/260521/3
authorAdrian Szyndela <adrian.s@samsung.com>
Mon, 28 Jun 2021 07:55:22 +0000 (09:55 +0200)
committerAdrian Szyndela <adrian.s@samsung.com>
Mon, 28 Jun 2021 09:34:48 +0000 (11:34 +0200)
It probably does not help much as it does not explain intentions.
They stay with the original authors of this code.

However, I believe it is a small step in the right direction.

Change-Id: I236a9b2b3dabb712ad7b1d0b6a8b1b33dd1e0230

src/common.c
src/peripheral_gpio.c

index d1a36b1..bf9a370 100644 (file)
@@ -6,6 +6,8 @@
 #include <sys/file.h>
 #include <system_info.h>
 
+#define UDEV_MONITOR_POLL_TIMEOUT_MILISECONDS 100
+
 int peripheral_lock(const char *file_name)
 {
        int fd = open(file_name, O_WRONLY | O_CLOEXEC);
@@ -97,7 +99,7 @@ int peripheral_wait_for_udev(struct udev_monitor *monitor, UdevCompareFunc func,
 
        for (int cnt = 0; cnt < 10; cnt++) {
                _D("poll iteration");
-               if (poll(&pfd, 1, 100) < 0) {
+               if (poll(&pfd, 1, UDEV_MONITOR_POLL_TIMEOUT_MILISECONDS) < 0) {
                        _E("Failed to watch udev monitor");
                        return -EIO;
                }
index cb99fba..6e8928b 100644 (file)
@@ -47,6 +47,8 @@ FEATURE("http://tizen.org/feature/peripheral_io.gpio")
 #define GPIO_INTERRUPTED_CALLBACK_UNSET 0
 #define GPIO_INTERRUPTED_CALLBACK_SET   1
 
+#define GPIO_INTERRUPTED_CALLBACK_CHECK_SET_INTERVAL_MILISECONDS 3000
+
 #define GPIO_BUFFER_MAX 64
 
 typedef struct _peripheral_gpio_interrupted_cb_info_s {
@@ -419,7 +421,7 @@ static gpointer __peripheral_gpio_poll(void *data)
 
        while (g_atomic_int_get(&gpio->cb_info.status) == GPIO_INTERRUPTED_CALLBACK_SET) {
 
-               poll_state = poll(&poll_fd, 1, 3000);
+               poll_state = poll(&poll_fd, 1, GPIO_INTERRUPTED_CALLBACK_CHECK_SET_INTERVAL_MILISECONDS);
 
                if (poll_state == 0)
                        continue;