feat: owloysius - dynamic init function invocator
[lunaix-os.git] / lunaix-os / kernel / device / poll.c
index e7f0f876a909ee602b17ce32d51b2067030f7bd2..ca204a28428dba9ab11da8b0fb9c270b8121257e 100644 (file)
@@ -37,7 +37,7 @@ __do_poll(struct poll_info* pinfo, int pld)
     struct device* dev;
     int evt = 0;
 
-    if ((dev = device_cast(poller->file_ref->inode->data))) {
+    if ((dev = resolve_device(poller->file_ref->inode->data))) {
         dev->ops.poll(dev);
     } else {
         // TODO handle generic file
@@ -111,7 +111,7 @@ __do_poll_all(struct poll_info* pinfo)
     return 0;
 }
 
-#define fd2dev(fd) device_cast((fd)->file->inode->data)
+#define fd2dev(fd) resolve_device((fd)->file->inode->data)
 
 static int
 __alloc_pld()
@@ -149,7 +149,7 @@ __append_pollers(int* ds, int npoller)
     return nc;
 }
 
-static int
+static void
 __wait_until_event()
 {
     block_current();
@@ -159,7 +159,7 @@ __wait_until_event()
 void
 iopoll_init(struct iopoll* ctx)
 {
-    ctx->pollers = valloc(sizeof(ptr_t) * MAX_POLLER_COUNT);
+    ctx->pollers = vzalloc(sizeof(ptr_t) * MAX_POLLER_COUNT);
     ctx->n_poller = 0;
 }
 
@@ -173,9 +173,9 @@ iopoll_free(pid_t pid, struct iopoll* ctx)
             llist_delete(&poller->evt_listener);
             vfree(poller);
         }
-
-        vfree(ctx->pollers);
     }
+    
+    vfree(ctx->pollers);
 }
 
 void
@@ -257,7 +257,7 @@ __DEFINE_LXSYSCALL2(int, pollctl, int, action, va_list, va)
 
             time_t t1 = clock_systime() + timeout;
             while (!(retcode == __do_poll_round(pinfos, npinfos))) {
-                if (timeout >= 0 && t1 >= clock_systime()) {
+                if (timeout >= 0 && t1 < clock_systime()) {
                     break;
                 }
                 __wait_until_event();
@@ -269,7 +269,7 @@ __DEFINE_LXSYSCALL2(int, pollctl, int, action, va_list, va)
 
             time_t t1 = clock_systime() + timeout;
             while (!(retcode == __do_poll_all(pinfo))) {
-                if (timeout >= 0 && t1 >= clock_systime()) {
+                if (timeout >= 0 && t1 < clock_systime()) {
                     break;
                 }
                 __wait_until_event();