2010-02-10 Rodrigo Kumpera <rkumpera@novell.com>
[mono.git] / mono / io-layer / handles-private.h
index ac85f069e2e8dbfbb668bb92f619f69c2beacf6d..b74d5bedf82f743a33566272c91762ddb1916d15 100644 (file)
@@ -139,6 +139,15 @@ static inline void _wapi_handle_set_signal_state (gpointer handle,
        if (state == TRUE) {
                /* Tell everyone blocking on a single handle */
 
+               /* The condition the global signal cond is waiting on is the signalling of
+                * _any_ handle. So lock it before setting the signalled state.
+                */
+               pthread_cleanup_push ((void(*)(void *))mono_mutex_unlock_in_cleanup, (void *)_wapi_global_signal_mutex);
+               thr_ret = mono_mutex_lock (_wapi_global_signal_mutex);
+               if (thr_ret != 0)
+                       g_warning ("Bad call to mono_mutex_lock result %d for global signal mutex", thr_ret);
+               g_assert (thr_ret == 0);
+
                /* This function _must_ be called with
                 * handle->signal_mutex locked
                 */
@@ -146,24 +155,29 @@ static inline void _wapi_handle_set_signal_state (gpointer handle,
                
                if (broadcast == TRUE) {
                        thr_ret = pthread_cond_broadcast (&handle_data->signal_cond);
+                       if (thr_ret != 0)
+                               g_warning ("Bad call to pthread_cond_broadcast result %d for handle %p", thr_ret, handle);
                        g_assert (thr_ret == 0);
                } else {
                        thr_ret = pthread_cond_signal (&handle_data->signal_cond);
+                       if (thr_ret != 0)
+                               g_warning ("Bad call to pthread_cond_signal result %d for handle %p", thr_ret, handle);
                        g_assert (thr_ret == 0);
                }
 
                /* Tell everyone blocking on multiple handles that something
                 * was signalled
-                */
-               pthread_cleanup_push ((void(*)(void *))mono_mutex_unlock_in_cleanup, (void *)_wapi_global_signal_mutex);
-               thr_ret = mono_mutex_lock (_wapi_global_signal_mutex);
-               g_assert (thr_ret == 0);
-                       
+                */                     
                thr_ret = pthread_cond_broadcast (_wapi_global_signal_cond);
+               if (thr_ret != 0)
+                       g_warning ("Bad call to pthread_cond_broadcast result %d for handle %p", thr_ret, handle);
                g_assert (thr_ret == 0);
                        
                thr_ret = mono_mutex_unlock (_wapi_global_signal_mutex);
+               if (thr_ret != 0)
+                       g_warning ("Bad call to mono_mutex_unlock result %d for global signal mutex", thr_ret);
                g_assert (thr_ret == 0);
+
                pthread_cleanup_pop (0);
        } else {
                handle_data->signalled=state;