[io-layer] Remove _wapi_handle_timedwait_signal
authorLudovic Henry <ludovic@xamarin.com>
Thu, 23 Jun 2016 10:03:32 +0000 (12:03 +0200)
committerLudovic Henry <ludovic@xamarin.com>
Thu, 23 Jun 2016 16:42:33 +0000 (18:42 +0200)
mono/io-layer/handles-private.h
mono/io-layer/handles.c
mono/io-layer/wait.c

index 4f20de02d411248bec7f67f5b4dc256d084696f1..c5123422e0cf8bda4f47f7edf443a48d741f1d3c 100644 (file)
@@ -32,6 +32,7 @@ extern struct _WapiHandleUnshared *_wapi_private_handles [];
 extern struct _WapiHandleSharedLayout *_wapi_shared_layout;
 
 extern guint32 _wapi_fd_reserve;
+extern gpointer _wapi_global_signal_handle;
 extern mono_mutex_t *_wapi_global_signal_mutex;
 extern pthread_cond_t *_wapi_global_signal_cond;
 extern int _wapi_sem_id;
@@ -76,8 +77,7 @@ extern gboolean _wapi_handle_count_signalled_handles (guint32 numhandles,
                                                      guint32 *lowest);
 extern void _wapi_handle_unlock_handles (guint32 numhandles,
                                         gpointer *handles);
-extern int _wapi_handle_timedwait_signal (guint32 timeout, gboolean poll, gboolean *alerted);
-extern int _wapi_handle_timedwait_signal_handle (gpointer handle, guint32 timeout, gboolean alertable, gboolean poll, gboolean *alerted);
+extern int _wapi_handle_timedwait_signal_handle (gpointer handle, guint32 timeout, gboolean poll, gboolean *alerted);
 extern gboolean _wapi_handle_get_or_set_share (guint64 device, guint64 inode,
                                               guint32 new_sharemode,
                                               guint32 new_access,
index a1df5bc4c603807a11b3a9dab580964e1fcc1ed7..26ddfc661f5793a25319b41af19a195c9410d813 100644 (file)
@@ -140,7 +140,7 @@ guint32 _wapi_fd_reserve;
  * Threads which wait for multiple handles wait on this one handle, and when a handle
  * is signalled, this handle is signalled too.
  */
-static gpointer _wapi_global_signal_handle;
+gpointer _wapi_global_signal_handle;
 
 /* Point to the mutex/cond inside _wapi_global_signal_handle */
 mono_mutex_t *_wapi_global_signal_mutex;
@@ -1471,12 +1471,6 @@ void _wapi_handle_unlock_handles (guint32 numhandles, gpointer *handles)
        }
 }
 
-int
-_wapi_handle_timedwait_signal (guint32 timeout, gboolean poll, gboolean *alerted)
-{
-       return _wapi_handle_timedwait_signal_handle (_wapi_global_signal_handle, timeout, TRUE, poll, alerted);
-}
-
 static void
 signal_handle_and_unref (gpointer handle)
 {
@@ -1503,14 +1497,11 @@ signal_handle_and_unref (gpointer handle)
 }
 
 int
-_wapi_handle_timedwait_signal_handle (gpointer handle, guint32 timeout, gboolean alertable, gboolean poll, gboolean *alerted)
+_wapi_handle_timedwait_signal_handle (gpointer handle, guint32 timeout, gboolean poll, gboolean *alerted)
 {
        MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: waiting for %p (type %s)", __func__, handle,
                   _wapi_handle_typename[_wapi_handle_type (handle)]);
 
-       if (alertable)
-               g_assert (alerted);
-
        if (alerted)
                *alerted = FALSE;
 
@@ -1520,29 +1511,21 @@ _wapi_handle_timedwait_signal_handle (gpointer handle, guint32 timeout, gboolean
                }
                if (timeout != INFINITE) {
                        if (timeout < 100) {
-                               /* FIXME: Real timeout is less than
-                                * 100ms time, but is it really worth
-                                * calculating to the exact ms?
-                                */
+                               /* FIXME: Real timeout is less than 100ms time, but is it really worth calculating to the exact ms? */
                                _wapi_handle_spin (100);
-
-                               if (WAPI_SHARED_HANDLE_DATA(handle).signalled == TRUE) {
-                                       return (0);
-                               } else {
-                                       return (ETIMEDOUT);
-                               }
+                               return WAPI_SHARED_HANDLE_DATA(handle).signalled ? 0 : ETIMEDOUT;
                        }
                }
+
                _wapi_handle_spin (100);
                return (0);
-               
        } else {
                guint32 idx = GPOINTER_TO_UINT(handle);
                int res;
                pthread_cond_t *cond;
                mono_mutex_t *mutex;
 
-               if (alertable) {
+               if (alerted) {
                        mono_thread_info_install_interrupt (signal_handle_and_unref, handle, alerted);
                        if (*alerted)
                                return 0;
@@ -1556,7 +1539,7 @@ _wapi_handle_timedwait_signal_handle (gpointer handle, guint32 timeout, gboolean
                        res = mono_os_cond_timedwait (cond, mutex, timeout);
                } else {
                        /* This is needed when waiting for process handles */
-                       if (!alertable) {
+                       if (!alerted) {
                                /*
                                 * pthread_cond_(timed)wait() can return 0 even if the condition was not
                                 * signalled.  This happens at least on Darwin.  We surface this, i.e., we
@@ -1581,7 +1564,7 @@ _wapi_handle_timedwait_signal_handle (gpointer handle, guint32 timeout, gboolean
                        }
                }
 
-               if (alertable) {
+               if (alerted) {
                        mono_thread_info_uninstall_interrupt (alerted);
                        if (!*alerted) {
                                /* if it is alerted, then the handle is unref in the interrupt callback */
index a91fff80d57c0697f6431d99b75fd9327a945433..e52ac8d90c719939c37c5431bc5ba986cd1d29f7 100644 (file)
@@ -176,7 +176,7 @@ guint32 WaitForSingleObjectEx(gpointer handle, guint32 timeout,
                }
 
                if (timeout == INFINITE) {
-                       waited = _wapi_handle_timedwait_signal_handle (handle, INFINITE, alertable, FALSE, &apc_pending);
+                       waited = _wapi_handle_timedwait_signal_handle (handle, INFINITE, FALSE, alertable ? &apc_pending : NULL);
                } else {
                        now = mono_100ns_ticks ();
                        if (end < now) {
@@ -184,7 +184,7 @@ guint32 WaitForSingleObjectEx(gpointer handle, guint32 timeout,
                                goto done;
                        }
 
-                       waited = _wapi_handle_timedwait_signal_handle (handle, (end - now) / 10 / 1000, alertable, FALSE, &apc_pending);
+                       waited = _wapi_handle_timedwait_signal_handle (handle, (end - now) / 10 / 1000, FALSE, alertable ? &apc_pending : NULL);
                }
 
                if(waited==0 && !apc_pending) {
@@ -359,7 +359,7 @@ guint32 SignalObjectAndWait(gpointer signal_handle, gpointer wait,
                }
 
                if (timeout == INFINITE) {
-                       waited = _wapi_handle_timedwait_signal_handle (wait, INFINITE, alertable, FALSE, &apc_pending);
+                       waited = _wapi_handle_timedwait_signal_handle (wait, INFINITE, FALSE, alertable ? &apc_pending : NULL);
                } else {
                        now = mono_100ns_ticks ();
                        if (end < now) {
@@ -367,7 +367,7 @@ guint32 SignalObjectAndWait(gpointer signal_handle, gpointer wait,
                                goto done;
                        }
 
-                       waited = _wapi_handle_timedwait_signal_handle (wait, (end - now) / 10 / 1000, alertable, FALSE, &apc_pending);
+                       waited = _wapi_handle_timedwait_signal_handle (wait, (end - now) / 10 / 1000, FALSE, alertable ? &apc_pending : NULL);
                }
 
                if (waited==0 && !apc_pending) {
@@ -606,13 +606,13 @@ guint32 WaitForMultipleObjectsEx(guint32 numobjects, gpointer *handles,
                if (!done) {
                        /* Enter the wait */
                        if (timeout == INFINITE) {
-                               ret = _wapi_handle_timedwait_signal (INFINITE, poll, &apc_pending);
+                               ret = _wapi_handle_timedwait_signal_handle (_wapi_global_signal_handle, INFINITE, poll, &apc_pending);
                        } else {
                                now = mono_100ns_ticks ();
                                if (end < now) {
                                        ret = WAIT_TIMEOUT;
                                } else {
-                                       ret = _wapi_handle_timedwait_signal ((end - now) / 10 / 1000, poll, &apc_pending);
+                                       ret = _wapi_handle_timedwait_signal_handle (_wapi_global_signal_handle, (end - now) / 10 / 1000, poll, &apc_pending);
                                }
                        }
                } else {