From 96c67c2e2fc61c98f8ab164873828bee3cf2e957 Mon Sep 17 00:00:00 2001 From: Ludovic Henry Date: Thu, 23 Jun 2016 12:03:32 +0200 Subject: [PATCH] [io-layer] Remove _wapi_handle_timedwait_signal --- mono/io-layer/handles-private.h | 4 ++-- mono/io-layer/handles.c | 33 ++++++++------------------------- mono/io-layer/wait.c | 12 ++++++------ 3 files changed, 16 insertions(+), 33 deletions(-) diff --git a/mono/io-layer/handles-private.h b/mono/io-layer/handles-private.h index 4f20de02d41..c5123422e0c 100644 --- a/mono/io-layer/handles-private.h +++ b/mono/io-layer/handles-private.h @@ -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, diff --git a/mono/io-layer/handles.c b/mono/io-layer/handles.c index a1df5bc4c60..26ddfc661f5 100644 --- a/mono/io-layer/handles.c +++ b/mono/io-layer/handles.c @@ -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 */ diff --git a/mono/io-layer/wait.c b/mono/io-layer/wait.c index a91fff80d57..e52ac8d90c7 100644 --- a/mono/io-layer/wait.c +++ b/mono/io-layer/wait.c @@ -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 { -- 2.25.1