[threads] Inline thread_cleanup into mono_thread_detach_internal (#4119)
[mono.git] / mono / metadata / threadpool-ms-io-poll.c
index f7ae6246f2fe1b0464f342c08562fd32e3a350c7..3d32130d3b530cc14ad38ce04cffaf5258ac28cf 100644 (file)
@@ -28,12 +28,6 @@ poll_init (gint wakeup_pipe_fd)
        return TRUE;
 }
 
-static void
-poll_cleanup (void)
-{
-       g_free (poll_fds);
-}
-
 static void
 poll_register_fd (gint fd, gint events, gboolean is_new)
 {
@@ -74,7 +68,7 @@ poll_register_fd (gint fd, gint events, gboolean is_new)
                poll_fds_capacity *= 2;
                g_assert (poll_fds_size <= poll_fds_capacity);
 
-               poll_fds = g_renew (mono_pollfd, poll_fds, poll_fds_capacity);
+               poll_fds = (mono_pollfd *)g_renew (mono_pollfd, poll_fds, poll_fds_capacity);
        }
 
        POLL_INIT_FD (&poll_fds [poll_fds_size - 1], fd, poll_event);
@@ -123,11 +117,7 @@ poll_mark_bad_fds (mono_pollfd *poll_fds, gint poll_fds_size)
                        ready++;
                        break;
                case -1:
-#if !defined(HOST_WIN32)
                        if (errno == EBADF)
-#else
-                       if (WSAGetLastError () == WSAEBADF)
-#endif
                        {
                                poll_fds [i].revents |= MONO_POLLNVAL;
                                ready++;
@@ -149,7 +139,9 @@ poll_event_wait (void (*callback) (gint fd, gint events, gpointer user_data), gp
 
        mono_gc_set_skip_thread (TRUE);
 
+       MONO_ENTER_GC_SAFE;
        ready = mono_poll (poll_fds, poll_fds_size, -1);
+       MONO_EXIT_GC_SAFE;
 
        mono_gc_set_skip_thread (FALSE);
 
@@ -167,37 +159,21 @@ poll_event_wait (void (*callback) (gint fd, gint events, gpointer user_data), gp
                 *  ENOMEM: we're doomed anyway
                 *
                 */
-#if !defined(HOST_WIN32)
                switch (errno)
-#else
-               switch (WSAGetLastError ())
-#endif
                {
-#if !defined(HOST_WIN32)
                case EINTR:
-#else
-               case WSAEINTR:
-#endif
                {
                        mono_thread_internal_check_for_interruption_critical (mono_thread_internal_current ());
                        ready = 0;
                        break;
                }
-#if !defined(HOST_WIN32)
                case EBADF:
-#else
-               case WSAEBADF:
-#endif
                {
                        ready = poll_mark_bad_fds (poll_fds, poll_fds_size);
                        break;
                }
                default:
-#if !defined(HOST_WIN32)
                        g_error ("poll_event_wait: mono_poll () failed, error (%d) %s", errno, g_strerror (errno));
-#else
-                       g_error ("poll_event_wait: mono_poll () failed, error (%d)\n", WSAGetLastError ());
-#endif
                        break;
                }
        }
@@ -236,7 +212,6 @@ poll_event_wait (void (*callback) (gint fd, gint events, gpointer user_data), gp
 
 static ThreadPoolIOBackend backend_poll = {
        .init = poll_init,
-       .cleanup = poll_cleanup,
        .register_fd = poll_register_fd,
        .remove_fd = poll_remove_fd,
        .event_wait = poll_event_wait,