Clear more threadpool state prior to domain unload.
authorRodrigo Kumpera <kumpera@gmail.com>
Fri, 13 Jul 2012 22:00:03 +0000 (19:00 -0300)
committerRodrigo Kumpera <kumpera@gmail.com>
Fri, 13 Jul 2012 22:04:18 +0000 (19:04 -0300)
* threadpool.c: When cleaning the threadpool
before a domain unload, clear the sock_to_state hashtbale
as it might contain objects of the dying domain.

mono/metadata/threadpool.c

index 272bd1bcdb9afa586e94c672635d9b05b0ff53c7..72a4574ef1f75be2f84e31061d51c4d05b6f73b5 100644 (file)
@@ -1109,6 +1109,24 @@ threadpool_clear_queue (ThreadPool *tp, MonoDomain *domain)
        }
 }
 
+static gboolean
+remove_sockstate_for_domain (gpointer key, gpointer value, gpointer user_data)
+{
+       MonoMList *list = value;
+       gboolean remove = FALSE;
+       while (list) {
+               MonoObject *data = mono_mlist_get_data (list);
+               if (mono_object_domain (data) == user_data) {
+                       MonoClass *class = mono_object_get_class (data);
+                       remove = TRUE;
+                       mono_mlist_set_data (list, NULL);
+               }
+               list = mono_mlist_next (list);
+       }
+       //FIXME is there some sort of additional unregistration we need to perform here?
+       return remove;
+}
+
 /*
  * Clean up the threadpool of all domain jobs.
  * Can only be called as part of the domain unloading process as
@@ -1126,6 +1144,11 @@ mono_thread_pool_remove_domain_jobs (MonoDomain *domain, int timeout)
        threadpool_clear_queue (&async_tp, domain);
        threadpool_clear_queue (&async_io_tp, domain);
 
+       EnterCriticalSection (&socket_io_data.io_lock);
+       mono_g_hash_table_foreach_remove (socket_io_data.sock_to_state, remove_sockstate_for_domain, domain);
+
+       LeaveCriticalSection (&socket_io_data.io_lock);
+       
        /*
         * There might be some threads out that could be about to execute stuff from the given domain.
         * We avoid that by setting up a semaphore to be pulsed by the thread that reaches zero.