[io-layer] Remove _wapi_thread_cur_apc_pending
authorLudovic Henry <ludovic@xamarin.com>
Thu, 7 Jul 2016 14:48:58 +0000 (16:48 +0200)
committerLudovic Henry <ludovic@xamarin.com>
Thu, 4 Aug 2016 13:40:25 +0000 (15:40 +0200)
mono/io-layer/io.c
mono/io-layer/sockets.c
mono/io-layer/thread-private.h
mono/io-layer/wthreads.c

index 2fc21d2a94ea5f891666103a5cff1806e7f38ce4..b01007e4cc05a8465980318694fe1397f7a2bc7b 100644 (file)
@@ -513,6 +513,7 @@ static gboolean file_read(gpointer handle, gpointer buffer,
        struct _WapiHandle_file *file_handle;
        gboolean ok;
        int fd, ret;
+       MonoThreadInfo *info = mono_thread_info_current ();
        
        ok=mono_w32handle_lookup (handle, MONO_W32HANDLE_FILE,
                                (gpointer *)&file_handle);
@@ -540,7 +541,7 @@ static gboolean file_read(gpointer handle, gpointer buffer,
        do {
                ret = read (fd, buffer, numbytes);
        } while (ret == -1 && errno == EINTR &&
-                !_wapi_thread_cur_apc_pending());
+                !mono_thread_info_is_interrupt_state (info));
                        
        if(ret==-1) {
                gint err = errno;
@@ -566,6 +567,7 @@ static gboolean file_write(gpointer handle, gconstpointer buffer,
        gboolean ok;
        int ret, fd;
        off_t current_pos = 0;
+       MonoThreadInfo *info = mono_thread_info_current ();
        
        ok=mono_w32handle_lookup (handle, MONO_W32HANDLE_FILE,
                                (gpointer *)&file_handle);
@@ -613,7 +615,7 @@ static gboolean file_write(gpointer handle, gconstpointer buffer,
        do {
                ret = write (fd, buffer, numbytes);
        } while (ret == -1 && errno == EINTR &&
-                !_wapi_thread_cur_apc_pending());
+                !mono_thread_info_is_interrupt_state (info));
        
        if (lock_while_writing) {
                _wapi_unlock_file_region (fd, current_pos, numbytes);
@@ -779,6 +781,7 @@ static gboolean file_setendoffile(gpointer handle)
        struct stat statbuf;
        off_t pos;
        int ret, fd;
+       MonoThreadInfo *info = mono_thread_info_current ();
        
        ok=mono_w32handle_lookup (handle, MONO_W32HANDLE_FILE,
                                (gpointer *)&file_handle);
@@ -839,7 +842,7 @@ static gboolean file_setendoffile(gpointer handle)
                do {
                        ret = write (fd, "", 1);
                } while (ret == -1 && errno == EINTR &&
-                        !_wapi_thread_cur_apc_pending());
+                        !mono_thread_info_is_interrupt_state (info));
 
                if(ret==-1) {
                        MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: handle %p extend write failed: %s", __func__, handle, strerror(errno));
@@ -868,7 +871,7 @@ static gboolean file_setendoffile(gpointer handle)
        do {
                ret=ftruncate(fd, pos);
        }
-       while (ret==-1 && errno==EINTR && !_wapi_thread_cur_apc_pending()); 
+       while (ret==-1 && errno==EINTR && !mono_thread_info_is_interrupt_state (info)); 
        if(ret==-1) {
                MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: handle %p ftruncate failed: %s", __func__,
                          handle, strerror(errno));
@@ -1202,6 +1205,7 @@ static gboolean console_read(gpointer handle, gpointer buffer,
        struct _WapiHandle_file *console_handle;
        gboolean ok;
        int ret, fd;
+       MonoThreadInfo *info = mono_thread_info_current ();
 
        ok=mono_w32handle_lookup (handle, MONO_W32HANDLE_CONSOLE,
                                (gpointer *)&console_handle);
@@ -1228,7 +1232,7 @@ static gboolean console_read(gpointer handle, gpointer buffer,
        
        do {
                ret=read(fd, buffer, numbytes);
-       } while (ret==-1 && errno==EINTR && !_wapi_thread_cur_apc_pending());
+       } while (ret==-1 && errno==EINTR && !mono_thread_info_is_interrupt_state (info));
 
        if(ret==-1) {
                MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: read of handle %p error: %s", __func__, handle,
@@ -1252,6 +1256,7 @@ static gboolean console_write(gpointer handle, gconstpointer buffer,
        struct _WapiHandle_file *console_handle;
        gboolean ok;
        int ret, fd;
+       MonoThreadInfo *info = mono_thread_info_current ();
        
        ok=mono_w32handle_lookup (handle, MONO_W32HANDLE_CONSOLE,
                                (gpointer *)&console_handle);
@@ -1278,7 +1283,7 @@ static gboolean console_write(gpointer handle, gconstpointer buffer,
        do {
                ret = write(fd, buffer, numbytes);
        } while (ret == -1 && errno == EINTR &&
-                !_wapi_thread_cur_apc_pending());
+                !mono_thread_info_is_interrupt_state (info));
 
        if (ret == -1) {
                if (errno == EINTR) {
@@ -1351,6 +1356,7 @@ static gboolean pipe_read (gpointer handle, gpointer buffer,
        struct _WapiHandle_file *pipe_handle;
        gboolean ok;
        int ret, fd;
+       MonoThreadInfo *info = mono_thread_info_current ();
 
        ok=mono_w32handle_lookup (handle, MONO_W32HANDLE_PIPE,
                                (gpointer *)&pipe_handle);
@@ -1380,7 +1386,7 @@ static gboolean pipe_read (gpointer handle, gpointer buffer,
 
        do {
                ret=read(fd, buffer, numbytes);
-       } while (ret==-1 && errno==EINTR && !_wapi_thread_cur_apc_pending());
+       } while (ret==-1 && errno==EINTR && !mono_thread_info_is_interrupt_state (info));
                
        if (ret == -1) {
                if (errno == EINTR) {
@@ -1411,6 +1417,7 @@ static gboolean pipe_write(gpointer handle, gconstpointer buffer,
        struct _WapiHandle_file *pipe_handle;
        gboolean ok;
        int ret, fd;
+       MonoThreadInfo *info = mono_thread_info_current ();
        
        ok=mono_w32handle_lookup (handle, MONO_W32HANDLE_PIPE,
                                (gpointer *)&pipe_handle);
@@ -1440,7 +1447,7 @@ static gboolean pipe_write(gpointer handle, gconstpointer buffer,
        do {
                ret = write (fd, buffer, numbytes);
        } while (ret == -1 && errno == EINTR &&
-                !_wapi_thread_cur_apc_pending());
+                !mono_thread_info_is_interrupt_state (info));
 
        if (ret == -1) {
                if (errno == EINTR) {
@@ -2024,6 +2031,7 @@ write_file (int src_fd, int dest_fd, struct stat *st_src, gboolean report_errors
        int remain, n;
        char *buf, *wbuf;
        int buf_size = st_src->st_blksize;
+       MonoThreadInfo *info = mono_thread_info_current ();
 
        buf_size = buf_size < 8192 ? 8192 : (buf_size > 65536 ? 65536 : buf_size);
        buf = (char *) malloc (buf_size);
@@ -2031,7 +2039,7 @@ write_file (int src_fd, int dest_fd, struct stat *st_src, gboolean report_errors
        for (;;) {
                remain = read (src_fd, buf, buf_size);
                if (remain < 0) {
-                       if (errno == EINTR && !_wapi_thread_cur_apc_pending ())
+                       if (errno == EINTR && !mono_thread_info_is_interrupt_state (info))
                                continue;
 
                        if (report_errors)
@@ -2047,7 +2055,7 @@ write_file (int src_fd, int dest_fd, struct stat *st_src, gboolean report_errors
                wbuf = buf;
                while (remain > 0) {
                        if ((n = write (dest_fd, wbuf, remain)) < 0) {
-                               if (errno == EINTR && !_wapi_thread_cur_apc_pending ())
+                               if (errno == EINTR && !mono_thread_info_is_interrupt_state (info))
                                        continue;
 
                                if (report_errors)
index bc4e032ef4e56ef7c23c7f4e4a5faab9a10f5969..05012d26fbbb505967a484272cb4ed1c99f6bad7 100644 (file)
@@ -85,6 +85,7 @@ static void socket_close (gpointer handle, gpointer data)
 {
        int ret;
        struct _WapiHandle_socket *socket_handle = (struct _WapiHandle_socket *)data;
+       MonoThreadInfo *info = mono_thread_info_current ();
 
        MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: closing socket handle %p", __func__, handle);
 
@@ -96,7 +97,7 @@ static void socket_close (gpointer handle, gpointer data)
        do {
                ret = close (GPOINTER_TO_UINT(handle));
        } while (ret == -1 && errno == EINTR &&
-                !_wapi_thread_cur_apc_pending ());
+                !mono_thread_info_is_interrupt_state (info));
        
        if (ret == -1) {
                gint errnum = errno;
@@ -174,6 +175,7 @@ guint32 _wapi_accept(guint32 fd, struct sockaddr *addr, socklen_t *addrlen)
        struct _WapiHandle_socket new_socket_handle = {0};
        gboolean ok;
        int new_fd;
+       MonoThreadInfo *info = mono_thread_info_current ();
 
        if (addr != NULL && *addrlen < sizeof(struct sockaddr)) {
                WSASetLastError (WSAEFAULT);
@@ -197,7 +199,7 @@ guint32 _wapi_accept(guint32 fd, struct sockaddr *addr, socklen_t *addrlen)
        do {
                new_fd = accept (fd, addr, addrlen);
        } while (new_fd == -1 && errno == EINTR &&
-                !_wapi_thread_cur_apc_pending());
+                !mono_thread_info_is_interrupt_state (info));
 
        if (new_fd == -1) {
                gint errnum = errno;
@@ -267,7 +269,8 @@ int _wapi_connect(guint32 fd, const struct sockaddr *serv_addr,
        struct _WapiHandle_socket *socket_handle;
        gboolean ok;
        gint errnum;
-       
+       MonoThreadInfo *info = mono_thread_info_current ();
+
        if (mono_w32handle_get_type (handle) != MONO_W32HANDLE_SOCKET) {
                WSASetLastError (WSAENOTSOCK);
                return(SOCKET_ERROR);
@@ -315,7 +318,7 @@ int _wapi_connect(guint32 fd, const struct sockaddr *serv_addr,
                fds.fd = fd;
                fds.events = MONO_POLLOUT;
                while (mono_poll (&fds, 1, -1) == -1 &&
-                      !_wapi_thread_cur_apc_pending ()) {
+                      !mono_thread_info_is_interrupt_state (info)) {
                        if (errno != EINTR) {
                                errnum = errno_to_WSA (errno, __func__);
 
@@ -512,6 +515,7 @@ int _wapi_recvfrom(guint32 fd, void *buf, size_t len, int recv_flags,
        struct _WapiHandle_socket *socket_handle;
        gboolean ok;
        int ret;
+       MonoThreadInfo *info = mono_thread_info_current ();
        
        if (mono_w32handle_get_type (handle) != MONO_W32HANDLE_SOCKET) {
                WSASetLastError (WSAENOTSOCK);
@@ -521,7 +525,7 @@ int _wapi_recvfrom(guint32 fd, void *buf, size_t len, int recv_flags,
        do {
                ret = recvfrom (fd, buf, len, recv_flags, from, fromlen);
        } while (ret == -1 && errno == EINTR &&
-                !_wapi_thread_cur_apc_pending ());
+                !mono_thread_info_is_interrupt_state (info));
 
        if (ret == 0 && len > 0) {
                /* According to the Linux man page, recvfrom only
@@ -569,6 +573,7 @@ _wapi_recvmsg(guint32 fd, struct msghdr *msg, int recv_flags)
        struct _WapiHandle_socket *socket_handle;
        gboolean ok;
        int ret;
+       MonoThreadInfo *info = mono_thread_info_current ();
        
        if (mono_w32handle_get_type (handle) != MONO_W32HANDLE_SOCKET) {
                WSASetLastError (WSAENOTSOCK);
@@ -578,7 +583,7 @@ _wapi_recvmsg(guint32 fd, struct msghdr *msg, int recv_flags)
        do {
                ret = recvmsg (fd, msg, recv_flags);
        } while (ret == -1 && errno == EINTR &&
-                !_wapi_thread_cur_apc_pending ());
+                !mono_thread_info_is_interrupt_state (info));
 
        if (ret == 0) {
                /* see _wapi_recvfrom */
@@ -606,6 +611,7 @@ int _wapi_send(guint32 fd, const void *msg, size_t len, int send_flags)
 {
        gpointer handle = GUINT_TO_POINTER (fd);
        int ret;
+       MonoThreadInfo *info = mono_thread_info_current ();
        
        if (mono_w32handle_get_type (handle) != MONO_W32HANDLE_SOCKET) {
                WSASetLastError (WSAENOTSOCK);
@@ -615,7 +621,7 @@ int _wapi_send(guint32 fd, const void *msg, size_t len, int send_flags)
        do {
                ret = send (fd, msg, len, send_flags);
        } while (ret == -1 && errno == EINTR &&
-                !_wapi_thread_cur_apc_pending ());
+                !mono_thread_info_is_interrupt_state (info));
 
        if (ret == -1) {
                gint errnum = errno;
@@ -643,6 +649,7 @@ int _wapi_sendto(guint32 fd, const void *msg, size_t len, int send_flags,
 {
        gpointer handle = GUINT_TO_POINTER (fd);
        int ret;
+       MonoThreadInfo *info = mono_thread_info_current ();
        
        if (mono_w32handle_get_type (handle) != MONO_W32HANDLE_SOCKET) {
                WSASetLastError (WSAENOTSOCK);
@@ -652,7 +659,7 @@ int _wapi_sendto(guint32 fd, const void *msg, size_t len, int send_flags,
        do {
                ret = sendto (fd, msg, len, send_flags, to, tolen);
        } while (ret == -1 && errno == EINTR &&
-                !_wapi_thread_cur_apc_pending ());
+                !mono_thread_info_is_interrupt_state (info));
 
        if (ret == -1) {
                gint errnum = errno;
@@ -671,6 +678,7 @@ _wapi_sendmsg(guint32 fd,  const struct msghdr *msg, int send_flags)
 {
        gpointer handle = GUINT_TO_POINTER (fd);
        int ret;
+       MonoThreadInfo *info = mono_thread_info_current ();
        
        if (mono_w32handle_get_type (handle) != MONO_W32HANDLE_SOCKET) {
                WSASetLastError (WSAENOTSOCK);
@@ -680,7 +688,7 @@ _wapi_sendmsg(guint32 fd,  const struct msghdr *msg, int send_flags)
        do {
                ret = sendmsg (fd, msg, send_flags);
        } while (ret == -1 && errno == EINTR &&
-                !_wapi_thread_cur_apc_pending ());
+                !mono_thread_info_is_interrupt_state (info));
 
        if (ret == -1) {
                gint errnum = errno;
@@ -967,6 +975,7 @@ static gboolean wapi_disconnectex (guint32 fd, WapiOverlapped *overlapped,
 static gint
 wapi_sendfile (guint32 socket, gpointer fd, guint32 bytes_to_write, guint32 bytes_per_send, guint32 flags)
 {
+       MonoThreadInfo *info = mono_thread_info_current ();
 #if defined(HAVE_SENDFILE) && (defined(__linux__) || defined(DARWIN))
        gint file = GPOINTER_TO_INT (fd);
        gint n;
@@ -989,7 +998,7 @@ wapi_sendfile (guint32 socket, gpointer fd, guint32 bytes_to_write, guint32 byte
                /* TODO: Might not send the entire file for non-blocking sockets */
                res = sendfile (file, socket, 0, &statbuf.st_size, NULL, 0);
 #endif
-       } while (res != -1 && errno == EINTR && !_wapi_thread_cur_apc_pending ());
+       } while (res != -1 && errno == EINTR && !mono_thread_info_is_interrupt_state (info));
        if (res == -1) {
                errnum = errno;
                errnum = errno_to_WSA (errnum, __func__);
@@ -1006,7 +1015,7 @@ wapi_sendfile (guint32 socket, gpointer fd, guint32 bytes_to_write, guint32 byte
        do {
                do {
                        n = read (file, buffer, SF_BUFFER_SIZE);
-               } while (n == -1 && errno == EINTR && !_wapi_thread_cur_apc_pending ());
+               } while (n == -1 && errno == EINTR && !mono_thread_info_is_interrupt_state (info));
                if (n == -1)
                        break;
                if (n == 0) {
@@ -1015,8 +1024,8 @@ wapi_sendfile (guint32 socket, gpointer fd, guint32 bytes_to_write, guint32 byte
                }
                do {
                        n = send (socket, buffer, n, 0); /* short sends? enclose this in a loop? */
-               } while (n == -1 && errno == EINTR && !_wapi_thread_cur_apc_pending ());
-       } while (n != -1 && errno == EINTR && !_wapi_thread_cur_apc_pending ());
+               } while (n == -1 && errno == EINTR && !mono_thread_info_is_interrupt_state (info));
+       } while (n != -1 && errno == EINTR && !mono_thread_info_is_interrupt_state (info));
 
        if (n == -1) {
                gint errnum = errno;
@@ -1295,6 +1304,7 @@ int _wapi_select(int nfds G_GNUC_UNUSED, fd_set *readfds, fd_set *writefds,
                 fd_set *exceptfds, struct timeval *timeout)
 {
        int ret, maxfd;
+       MonoThreadInfo *info = mono_thread_info_current ();
        
        for (maxfd = FD_SETSIZE-1; maxfd >= 0; maxfd--) {
                if ((readfds && FD_ISSET (maxfd, readfds)) ||
@@ -1313,7 +1323,7 @@ int _wapi_select(int nfds G_GNUC_UNUSED, fd_set *readfds, fd_set *writefds,
                ret = select(maxfd + 1, readfds, writefds, exceptfds,
                             timeout);
        } while (ret == -1 && errno == EINTR &&
-                !_wapi_thread_cur_apc_pending ());
+                !mono_thread_info_is_interrupt_state (info));
 
        if (ret == -1) {
                gint errnum = errno;
index 0f124656583f6e2cda369c3aa7a591def2cbcee4..c5bb6cf3dfba4cabf2f982c9f77c2ec16f64d9bc 100644 (file)
@@ -22,7 +22,6 @@
 void
 _wapi_thread_init (void);
 
-extern gboolean _wapi_thread_cur_apc_pending (void);
 extern void _wapi_thread_cleanup (void);
 
 #endif /* _WAPI_THREAD_PRIVATE_H_ */
index 302d60249ca7f6ea892e595e912f178009fa55e4..e7a7e54b9d7d1d328b4b65b266b282aebb1ee221 100644 (file)
@@ -147,12 +147,6 @@ wapi_ref_thread_handle (gpointer handle)
        mono_w32handle_ref (handle);
 }
 
-gboolean
-_wapi_thread_cur_apc_pending (void)
-{
-       return mono_thread_info_is_interrupt_state (mono_thread_info_current ());
-}
-
 void
 wapi_thread_own_mutex (gpointer mutex)
 {