Add g_assert_not_reached () to mono_gc_pthread_exit ().
[mono.git] / mono / metadata / tpool-epoll.c
index 7c94652629b796e82e3b0fdfe4ffd63e9f719c0f..41242c6b5e9fda1afca864de7c71a3ecc6d0df82 100644 (file)
@@ -7,6 +7,7 @@
  *
  * Copyright 2001-2003 Ximian, Inc (http://www.ximian.com)
  * Copyright 2004-2011 Novell, Inc (http://www.novell.com)
+ * Copyright 2011 Xamarin Inc (http://www.xamarin.com)
  */
 
 struct _tp_epoll_data {
@@ -14,7 +15,7 @@ struct _tp_epoll_data {
 };
 
 typedef struct _tp_epoll_data tp_epoll_data;
-static void tp_epoll_modify (gpointer event_data, int fd, int operation, int events, gboolean is_new);
+static void tp_epoll_modify (gpointer p, int fd, int operation, int events, gboolean is_new);
 static void tp_epoll_shutdown (gpointer event_data);
 static void tp_epoll_wait (gpointer event_data);
 
@@ -30,8 +31,18 @@ tp_epoll_init (SocketIOData *data)
        result->epollfd = epoll_create (256); /* The number does not really matter */
        fcntl (result->epollfd, F_SETFD, FD_CLOEXEC);
 #endif
-       if (result->epollfd == -1)
+       if (result->epollfd == -1) {
+               int err = errno;
+               if (g_getenv ("MONO_DEBUG")) {
+#ifdef EPOLL_CLOEXEC
+                       g_message ("epoll_create1(EPOLL_CLOEXEC) failed: %d %s", err, g_strerror (err));
+#else
+                       g_message ("epoll_create(256) failed: %d %s", err, g_strerror (err));
+#endif
+               }
+
                return NULL;
+       }
 
        data->shutdown = tp_epoll_shutdown;
        data->modify = tp_epoll_modify;
@@ -40,12 +51,17 @@ tp_epoll_init (SocketIOData *data)
 }
 
 static void
-tp_epoll_modify (gpointer event_data, int fd, int operation, int events, gboolean is_new)
+tp_epoll_modify (gpointer p, int fd, int operation, int events, gboolean is_new)
 {
-       tp_epoll_data *data = event_data;
+       SocketIOData *socket_io_data;
+       tp_epoll_data *data;
        struct epoll_event evt;
        int epoll_op;
 
+       socket_io_data = p;
+       data = socket_io_data->event_data;
+
+       memset (&evt, 0, sizeof (evt));
        evt.data.fd = fd;
        if ((events & MONO_POLLIN) != 0)
                evt.events |= EPOLLIN;
@@ -62,6 +78,7 @@ tp_epoll_modify (gpointer event_data, int fd, int operation, int events, gboolea
                        }
                }
        }
+       LeaveCriticalSection (&socket_io_data->io_lock);
 }
 
 static void
@@ -80,7 +97,6 @@ tp_epoll_wait (gpointer p)
 {
        SocketIOData *socket_io_data;
        int epollfd;
-       MonoInternalThread *thread;
        struct epoll_event *events, *evt;
        int ready = 0, i;
        gpointer async_results [EPOLL_NEVENTS * 2]; // * 2 because each loop can add up to 2 results here
@@ -90,18 +106,20 @@ tp_epoll_wait (gpointer p)
        socket_io_data = p;
        data = socket_io_data->event_data;
        epollfd = data->epollfd;
-       thread = mono_thread_internal_current ();
        events = g_new0 (struct epoll_event, EPOLL_NEVENTS);
 
        while (1) {
+               mono_gc_set_skip_thread (TRUE);
+
                do {
                        if (ready == -1) {
-                               if (THREAD_WANTS_A_BREAK (thread))
-                                       mono_thread_interruption_checkpoint ();
+                               check_for_interruption_critical ();
                        }
                        ready = epoll_wait (epollfd, events, EPOLL_NEVENTS, -1);
                } while (ready == -1 && errno == EINTR);
 
+               mono_gc_set_skip_thread (FALSE);
+
                if (ready == -1) {
                        int err = errno;
                        g_free (events);
@@ -159,7 +177,7 @@ tp_epoll_wait (gpointer p)
                }
                LeaveCriticalSection (&socket_io_data->io_lock);
                threadpool_append_jobs (&async_io_tp, (MonoObject **) async_results, nresults);
-               mono_gc_bzero (async_results, sizeof (gpointer) * nresults);
+               mono_gc_bzero_aligned (async_results, sizeof (gpointer) * nresults);
        }
 }
 #undef EPOLL_NEVENTS