Author: gonzalo
Date: 2005-05-02 02:54:57 -0400 (Mon, 02 May 2005)
New Revision: 43864
Added:
trunk/mono/mono/metadata/threadpool-internals.h
Modified:
trunk/mono/mono/metadata/ChangeLog
trunk/mono/mono/metadata/Makefile.am
trunk/mono/mono/metadata/socket-io.c
trunk/mono/mono/metadata/threadpool.c
Log:
2005-05-02 Gonzalo Paniagua Javier <[EMAIL PROTECTED]>
* threadpool-internals.h:
* Makefile.am: added threadpool-internals.h
* threadpool.c: call mono_unhandled_exception on exceptions not handled
that happen in threadpool threads (tested on MS).
(mono_thread_pool_remove_socket): new function that dispatch any pending
AIO call on a socket that is closing. By now only epoll really needs it,
as select/poll wake up when the socket closes.
* socket-io.c: call mono_thread_pool_remove_socket in Close_internal.
Modified: trunk/mono/mono/metadata/ChangeLog
===================================================================
--- trunk/mono/mono/metadata/ChangeLog 2005-05-02 06:00:00 UTC (rev 43863)
+++ trunk/mono/mono/metadata/ChangeLog 2005-05-02 06:54:57 UTC (rev 43864)
@@ -1,3 +1,17 @@
+2005-05-02 Gonzalo Paniagua Javier <[EMAIL PROTECTED]>
+
+ * threadpool-internals.h:
+ * Makefile.am: added threadpool-internals.h
+
+ * threadpool.c: call mono_unhandled_exception on exceptions not handled
+ that happen in threadpool threads (tested on MS).
+ (mono_thread_pool_remove_socket): new function that dispatch any pending
+ AIO call on a socket that is closing. By now only epoll really needs it,
+ as select/poll wake up when the socket closes.
+
+
+ * socket-io.c: call mono_thread_pool_remove_socket in Close_internal.
+
2005-05-01 Zoltan Varga <[EMAIL PROTECTED]>
* marshal.c (mono_marshal_get_managed_wrapper): Handle changing the
calling convention.
Modified: trunk/mono/mono/metadata/Makefile.am
===================================================================
--- trunk/mono/mono/metadata/Makefile.am 2005-05-02 06:00:00 UTC (rev
43863)
+++ trunk/mono/mono/metadata/Makefile.am 2005-05-02 06:54:57 UTC (rev
43864)
@@ -61,6 +61,7 @@
threads-types.h \
threadpool.c \
threadpool.h \
+ threadpool-internals.h \
file-io.c \
file-io.h \
socket-io.c \
Modified: trunk/mono/mono/metadata/socket-io.c
===================================================================
--- trunk/mono/mono/metadata/socket-io.c 2005-05-02 06:00:00 UTC (rev
43863)
+++ trunk/mono/mono/metadata/socket-io.c 2005-05-02 06:54:57 UTC (rev
43864)
@@ -666,7 +666,10 @@
#endif
*error = 0;
-
+
+ /* Clear any pending work item from this socket if the underlying
+ * polling system does not notify when the socket is closed */
+ mono_thread_pool_remove_socket (GPOINTER_TO_INT (sock));
closesocket(sock);
}
Added: trunk/mono/mono/metadata/threadpool-internals.h
===================================================================
--- trunk/mono/mono/metadata/threadpool-internals.h 2005-05-02 06:00:00 UTC
(rev 43863)
+++ trunk/mono/mono/metadata/threadpool-internals.h 2005-05-02 06:54:57 UTC
(rev 43864)
@@ -0,0 +1,5 @@
+#ifndef _MONO_THREADPOOL_INTERNALS_H_
+#define _MONO_THREADPOOL_INTERNALS_H_
+
+void mono_thread_pool_remove_socket (int sock);
+#endif
Modified: trunk/mono/mono/metadata/threadpool.c
===================================================================
--- trunk/mono/mono/metadata/threadpool.c 2005-05-02 06:00:00 UTC (rev
43863)
+++ trunk/mono/mono/metadata/threadpool.c 2005-05-02 06:54:57 UTC (rev
43864)
@@ -24,6 +24,7 @@
#include <mono/metadata/tabledefs.h>
#include <mono/metadata/threads.h>
#include <mono/metadata/threads-types.h>
+#include <mono/metadata/threadpool-internals.h>
#include <mono/metadata/exception.h>
#include <mono/metadata/file-io.h>
#include <mono/metadata/monitor.h>
@@ -125,6 +126,8 @@
AIO_OP_RECEIVEFROM,
AIO_OP_SEND,
AIO_OP_SENDTO,
+ AIO_OP_RECV_JUST_CALLBACK,
+ AIO_OP_SEND_JUST_CALLBACK,
AIO_OP_LAST
};
@@ -172,9 +175,11 @@
switch (state->operation) {
case AIO_OP_ACCEPT:
case AIO_OP_RECEIVE:
+ case AIO_OP_RECV_JUST_CALLBACK:
case AIO_OP_RECEIVEFROM:
return MONO_POLLIN;
case AIO_OP_SEND:
+ case AIO_OP_SEND_JUST_CALLBACK:
case AIO_OP_SENDTO:
case AIO_OP_CONNECT:
return MONO_POLLOUT;
@@ -237,8 +242,13 @@
domain = ((MonoObject *)ar)->vtable->domain;
if (mono_domain_set (domain, FALSE)) {
+ ASyncCall *ac;
+
mono_thread_push_appdomain_ref (domain);
mono_async_invoke (ar);
+ ac = (ASyncCall *) ar->data;
+ if (ac->msg->exc != NULL)
+ mono_unhandled_exception (ac->msg->exc);
mono_thread_pop_appdomain_ref ();
}
InterlockedDecrement (&busy_io_worker_threads);
@@ -597,6 +607,44 @@
}
#endif
+/*
+ * select/poll wake up when a socket is closed, but epoll just removes
+ * the socket from its internal list without notification.
+ */
+void
+mono_thread_pool_remove_socket (int sock)
+{
+#ifdef HAVE_EPOLL
+ GSList *list, *next;
+ MonoSocketAsyncResult *state;
+
+ if (socket_io_data.epoll_disabled == TRUE || socket_io_data.inited ==
FALSE)
+ return;
+
+ EnterCriticalSection (&socket_io_data.io_lock);
+ list = g_hash_table_lookup (socket_io_data.sock_to_state,
GINT_TO_POINTER (sock));
+ if (list) {
+ g_hash_table_remove (socket_io_data.sock_to_state,
GINT_TO_POINTER (sock));
+ }
+ LeaveCriticalSection (&socket_io_data.io_lock);
+
+ while (list) {
+ state = (MonoSocketAsyncResult *) list->data;
+ if (state->operation == AIO_OP_RECEIVE)
+ state->operation = AIO_OP_RECV_JUST_CALLBACK;
+ else if (state->operation == AIO_OP_SEND)
+ state->operation = AIO_OP_SEND_JUST_CALLBACK;
+
+ next = g_slist_remove_link (list, list);
+ list = process_io_event (list, MONO_POLLIN);
+ if (list)
+ process_io_event (list, MONO_POLLOUT);
+
+ list = next;
+ }
+#endif
+}
+
#ifdef PLATFORM_WIN32
static void
connect_hack (gpointer x)
@@ -814,14 +862,11 @@
MonoImage *system_assembly = mono_image_loaded ("System");
if (system_assembly == NULL)
- return FALSE;
+ g_assert_not_reached ();
klass = mono_class_from_name (system_assembly,
"System.Net.Sockets", "Socket/SocketAsyncCall");
- if (klass == NULL) {
- /* Should never happen... */
- g_print ("socket_io_filter: SocketAsyncCall class not
found.\n");
- return FALSE;
- }
+ if (klass == NULL)
+ g_assert_not_reached ();
InterlockedCompareExchangePointer ((gpointer *)
&socket_async_call_klass, klass, NULL);
}
@@ -1077,8 +1122,13 @@
* so we need to set the right domain here */
domain = ((MonoObject *)ar)->vtable->domain;
if (mono_domain_set (domain, FALSE)) {
+ ASyncCall *ac;
+
mono_thread_push_appdomain_ref (domain);
mono_async_invoke (ar);
+ ac = (ASyncCall *) ar->data;
+ if (ac->msg->exc != NULL)
+ mono_unhandled_exception (ac->msg->exc);
mono_thread_pop_appdomain_ref ();
}
InterlockedDecrement (&busy_worker_threads);
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches