Author: dick
Date: 2006-08-10 12:55:37 -0400 (Thu, 10 Aug 2006)
New Revision: 63607

Modified:
   trunk/mono/mono/io-layer/ChangeLog
   trunk/mono/mono/io-layer/threads.c
Log:

2006-08-10  Dick Porter  <[EMAIL PROTECTED]>

        * threads.c (_wapi_thread_queue_apc)
        (_wapi_thread_dispatch_apc_queue): Use a process-local mutex here
        instead of the cross process semaphore.  We already check that
        access to the APC queue is within the owning process so there's no
        need to protect from other processes.  Avoids a global deadlock
        when a thread is aborted while it holds the handle semaphore
        locked.
        (_wapi_thread_apc_pending): Hide an annoying message which can
        happen if a thread handle has been blown away at process shutdown
        while it is in an alertable wait.

        Both problems seen while shutting down monodevelop.




Modified: trunk/mono/mono/io-layer/ChangeLog
===================================================================
--- trunk/mono/mono/io-layer/ChangeLog  2006-08-10 16:53:46 UTC (rev 63606)
+++ trunk/mono/mono/io-layer/ChangeLog  2006-08-10 16:55:37 UTC (rev 63607)
@@ -1,3 +1,18 @@
+2006-08-10  Dick Porter  <[EMAIL PROTECTED]>
+
+       * threads.c (_wapi_thread_queue_apc)
+       (_wapi_thread_dispatch_apc_queue): Use a process-local mutex here
+       instead of the cross process semaphore.  We already check that
+       access to the APC queue is within the owning process so there's no
+       need to protect from other processes.  Avoids a global deadlock
+       when a thread is aborted while it holds the handle semaphore
+       locked.
+       (_wapi_thread_apc_pending): Hide an annoying message which can
+       happen if a thread handle has been blown away at process shutdown
+       while it is in an alertable wait.
+
+       Both problems seen while shutting down monodevelop.
+
 2006-07-25  Dick Porter  <[EMAIL PROTECTED]>
 
        * shared.c (_wapi_shm_file): Remove '/' characters from the uname

Modified: trunk/mono/mono/io-layer/threads.c
===================================================================
--- trunk/mono/mono/io-layer/threads.c  2006-08-10 16:53:46 UTC (rev 63606)
+++ trunk/mono/mono/io-layer/threads.c  2006-08-10 16:55:37 UTC (rev 63607)
@@ -1020,6 +1020,8 @@
        SleepEx(ms, FALSE);
 }
 
+static mono_mutex_t apc_mutex = MONO_MUTEX_INITIALIZER;
+
 gboolean _wapi_thread_cur_apc_pending (void)
 {
        gpointer thread = _wapi_thread_handle_from_id (pthread_self ());
@@ -1047,12 +1049,16 @@
        apc->callback = apc_callback;
        apc->param = param;
        
-       thr_ret = _wapi_handle_lock_shared_handles ();
+       pthread_cleanup_push ((void(*)(void *))mono_mutex_unlock_in_cleanup,
+                             (void *)&apc_mutex);
+       thr_ret = mono_mutex_lock (&apc_mutex);
        g_assert (thr_ret == 0);
        
        thread->apc_queue = g_slist_append (thread->apc_queue, apc);
        
-       _wapi_handle_unlock_shared_handles ();
+       thr_ret = mono_mutex_unlock (&apc_mutex);
+       g_assert (thr_ret == 0);
+       pthread_cleanup_pop (0);
 }
 
 gboolean _wapi_thread_apc_pending (gpointer handle)
@@ -1063,8 +1069,16 @@
        ok = _wapi_lookup_handle (handle, WAPI_HANDLE_THREAD,
                                  (gpointer *)&thread);
        if (ok == FALSE) {
+#ifdef DEBUG
+               /* This might happen at process shutdown, as all
+                * thread handles are forcibly closed.  If a thread
+                * still has an alertable wait the final
+                * _wapi_thread_apc_pending check will probably fail
+                * to find the handle
+                */
                g_warning ("%s: error looking up thread handle %p", __func__,
                           handle);
+#endif
                return (FALSE);
        }
        
@@ -1095,14 +1109,18 @@
                return(FALSE);
        }
        
-       thr_ret = _wapi_handle_lock_shared_handles ();
+       pthread_cleanup_push ((void(*)(void *))mono_mutex_unlock_in_cleanup,
+                             (void *)&apc_mutex);
+       thr_ret = mono_mutex_lock (&apc_mutex);
        g_assert (thr_ret == 0);
        
        list = thread->apc_queue;
        thread->apc_queue = NULL;
        
-       _wapi_handle_unlock_shared_handles ();
-       
+       thr_ret = mono_mutex_unlock (&apc_mutex);
+       g_assert (thr_ret == 0);
+       pthread_cleanup_pop (0);
+
        while (list != NULL) {
                apc = (ApcInfo *)list->data;
                apc->callback (apc->param);

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to