Merge pull request #3663 from lateralusX/jlorenss/win-api-family-support-libgcmonosgen
[mono.git] / mono / metadata / threads.c
index fdb6934036b3eadbe8c1263642f9d70083ef205d..3921c7e352205fb6d5e6ec98707f916181118e57 100644 (file)
@@ -2933,34 +2933,14 @@ wait_for_tids (struct wait_data *wait, guint32 timeout)
                return;
 
        for(i=0; i<wait->num; i++) {
-               gsize tid = wait->threads[i]->tid;
+               MonoInternalThread *internal;
 
-               /*
-                * On !win32, when the thread handle becomes signalled, it just means the thread has exited user code,
-                * it can still run io-layer etc. code. So wait for it to really exit.
-                * FIXME: This won't join threads which are not in the joinable_hash yet.
-                */
-               mono_thread_join ((gpointer)tid);
+               internal = wait->threads [i];
 
                mono_threads_lock ();
-               if(mono_g_hash_table_lookup (threads, (gpointer)tid)!=NULL) {
-                       /* This thread must have been killed, because
-                        * it hasn't cleaned itself up. (It's just
-                        * possible that the thread exited before the
-                        * parent thread had a chance to store the
-                        * handle, and now there is another pointer to
-                        * the already-exited thread stored.  In this
-                        * case, we'll just get two
-                        * mono_profiler_thread_end() calls for the
-                        * same thread.)
-                        */
-       
-                       mono_threads_unlock ();
-                       THREAD_DEBUG (g_message ("%s: cleaning up after thread %p (%"G_GSIZE_FORMAT")", __func__, wait->threads[i], tid));
-                       thread_cleanup (wait->threads[i]);
-               } else {
-                       mono_threads_unlock ();
-               }
+               if (mono_g_hash_table_lookup (threads, (gpointer) internal->tid) == internal)
+                       g_error ("%s: failed to call mono_thread_detach_internal on thread %p, InternalThread: %p", __func__, internal->tid, internal);
+               mono_threads_unlock ();
        }
 }
 
@@ -2996,15 +2976,14 @@ static void wait_for_tids_or_state_change (struct wait_data *wait, guint32 timeo
                return;
        
        if (ret < wait->num) {
-               gsize tid = wait->threads[ret]->tid;
+               MonoInternalThread *internal;
+
+               internal = wait->threads [ret];
+
                mono_threads_lock ();
-               if (mono_g_hash_table_lookup (threads, (gpointer)tid)!=NULL) {
-                       /* See comment in wait_for_tids about thread cleanup */
-                       mono_threads_unlock ();
-                       THREAD_DEBUG (g_message ("%s: cleaning up after thread %"G_GSIZE_FORMAT, __func__, tid));
-                       thread_cleanup (wait->threads [ret]);
-               } else
-                       mono_threads_unlock ();
+               if (mono_g_hash_table_lookup (threads, (gpointer) internal->tid) == internal)
+                       g_error ("%s: failed to call mono_thread_detach_internal on thread %p, InternalThread: %p", __func__, internal->tid, internal);
+               mono_threads_unlock ();
        }
 }