[runtime] Move caches present in both MonoImage and MonoImageSet into an embedded...
[mono.git] / mono / metadata / threadpool-ms-io-poll.c
index 7e0e1f42e5a11958598ea887f4fe19acc3e80765..88bdc9f839be81a2bdcff84a7f8ae9207143ca55 100644 (file)
@@ -68,19 +68,25 @@ poll_mark_bad_fds (mono_pollfd *poll_fds, gint poll_fds_size)
 }
 
 static void
-poll_update_add (ThreadPoolIOUpdate *update)
+poll_register_fd (gint fd, gint events, gboolean is_new)
 {
        gboolean found = FALSE;
        gint j, k;
 
        for (j = 1; j < poll_fds_size; ++j) {
                mono_pollfd *poll_fd = poll_fds + j;
-               if (poll_fd->fd == update->fd) {
+               if (poll_fd->fd == fd) {
                        found = TRUE;
                        break;
                }
        }
 
+       if (events == 0) {
+               if (found)
+                       POLL_INIT_FD (poll_fds + j, -1, 0);
+               return;
+       }
+
        if (!found) {
                for (j = 1; j < poll_fds_capacity; ++j) {
                        mono_pollfd *poll_fd = poll_fds + j;
@@ -96,7 +102,7 @@ poll_update_add (ThreadPoolIOUpdate *update)
                        POLL_INIT_FD (poll_fds + k, -1, 0);
        }
 
-       POLL_INIT_FD (poll_fds + j, update->fd, update->events);
+       POLL_INIT_FD (poll_fds + j, fd, events);
 
        if (j >= poll_fds_size)
                poll_fds_size = j + 1;
@@ -133,7 +139,7 @@ poll_event_wait (void)
 #else
                case WSAEINTR:
 #endif
-                       check_for_interruption_critical ();
+                       mono_thread_internal_check_for_interruption_critical (mono_thread_internal_current ());
                        ready = 0;
                        break;
 #if !defined(HOST_WIN32)
@@ -156,58 +162,30 @@ poll_event_wait (void)
        return ready;
 }
 
-static inline gint
-poll_event_fd_at (guint i)
+static gint
+poll_event_get_fd_at (gint i, gint *events)
 {
-       return poll_fds [i].fd;
+       g_assert (events);
+
+       *events = ((poll_fds [i].revents & (MONO_POLLIN | MONO_POLLERR | MONO_POLLHUP | MONO_POLLNVAL)) ? MONO_POLLIN : 0)
+                   | ((poll_fds [i].revents & (MONO_POLLOUT | MONO_POLLERR | MONO_POLLHUP | MONO_POLLNVAL)) ? MONO_POLLOUT : 0);
+
+       /* if nothing happened on the fd, then just return
+        * an invalid fd number so it is discarded */
+       return poll_fds [i].revents == 0 ? -1 : poll_fds [i].fd;
 }
 
 static gint
-poll_event_max (void)
+poll_event_get_fd_max (void)
 {
        return poll_fds_size;
 }
 
-static gboolean
-poll_event_create_sockares_at (guint i, gint fd, MonoMList **list)
-{
-       mono_pollfd *poll_fd;
-
-       g_assert (list);
-
-       poll_fd = &poll_fds [i];
-       g_assert (poll_fd);
-
-       g_assert (fd == poll_fd->fd);
-
-       if (fd == -1 || poll_fd->revents == 0)
-               return FALSE;
-
-       if (*list && (poll_fd->revents & (MONO_POLLIN | MONO_POLLERR | MONO_POLLHUP | MONO_POLLNVAL)) != 0) {
-               MonoSocketAsyncResult *io_event = get_sockares_for_event (list, MONO_POLLIN);
-               if (io_event)
-                       mono_threadpool_ms_enqueue_work_item (((MonoObject*) io_event)->vtable->domain, (MonoObject*) io_event);
-       }
-       if (*list && (poll_fd->revents & (MONO_POLLOUT | MONO_POLLERR | MONO_POLLHUP | MONO_POLLNVAL)) != 0) {
-               MonoSocketAsyncResult *io_event = get_sockares_for_event (list, MONO_POLLOUT);
-               if (io_event)
-                       mono_threadpool_ms_enqueue_work_item (((MonoObject*) io_event)->vtable->domain, (MonoObject*) io_event);
-       }
-
-       if (*list)
-               poll_fd->events = get_events (*list);
-       else
-               POLL_INIT_FD (poll_fd, -1, 0);
-
-       return TRUE;
-}
-
 static ThreadPoolIOBackend backend_poll = {
        .init = poll_init,
        .cleanup = poll_cleanup,
-       .update_add = poll_update_add,
+       .register_fd = poll_register_fd,
        .event_wait = poll_event_wait,
-       .event_max = poll_event_max,
-       .event_fd_at = poll_event_fd_at,
-       .event_create_sockares_at = poll_event_create_sockares_at,
+       .event_get_fd_max = poll_event_get_fd_max,
+       .event_get_fd_at = poll_event_get_fd_at,
 };