diff --git a/src/mercury_core.c b/src/mercury_core.c index 9f4135f5..3cb40af2 100644 --- a/src/mercury_core.c +++ b/src/mercury_core.c @@ -922,6 +922,12 @@ hg_core_completion_count(const struct hg_core_private_context *context); static void hg_core_completion_trigger(struct hg_completion_entry *hg_completion_entry); +/** + * Check for events on loopback and if it is safe to wait. + */ +static HG_INLINE bool +hg_core_event_ready_loopback(struct hg_core_private_context *context); + /** * Make progress. */ @@ -5237,6 +5243,22 @@ hg_core_completion_trigger(struct hg_completion_entry *hg_completion_entry) } } +/*---------------------------------------------------------------------------*/ +static HG_INLINE bool +hg_core_event_ready_loopback(struct hg_core_private_context *context) +{ + if (context->loopback_notify.event > 0) { + /* We will need to notify the event if we're waiting */ + hg_atomic_cas32(&context->loopback_notify.must_notify, 0, 1); + if (hg_core_completion_count(context) > 0) { + hg_atomic_cas32(&context->loopback_notify.must_notify, 1, 0); + return true; + } + } + + return false; +} + /*---------------------------------------------------------------------------*/ static hg_return_t hg_core_progress_wait( @@ -7022,21 +7044,27 @@ HG_Core_event_get_wait_fd(const hg_core_context_t *context) /*---------------------------------------------------------------------------*/ bool -HG_Core_event_ready_loopback(hg_core_context_t *context) +HG_Core_event_ready(hg_core_context_t *context) { struct hg_core_private_context *private_context = (struct hg_core_private_context *) context; - if (private_context->loopback_notify.event > 0) { - /* We will need to notify the event if we're waiting */ - hg_atomic_cas32(&private_context->loopback_notify.must_notify, 0, 1); - if (hg_core_completion_count(private_context) > 0) { - hg_atomic_cas32( - &private_context->loopback_notify.must_notify, 1, 0); - return true; - } - } + HG_CHECK_SUBSYS_ERROR_NORET( + poll, context == NULL, error, "NULL HG core context"); + if (hg_core_completion_count(private_context) > 0) + return true; +#ifdef NA_HAS_SM + if ((context->core_class->na_sm_class != NULL) && + !NA_Poll_try_wait( + context->core_class->na_sm_class, context->na_sm_context)) + return true; +#endif + if (!NA_Poll_try_wait(context->core_class->na_class, context->na_context)) + return true; + return hg_core_event_ready_loopback(private_context); + +error: return false; } diff --git a/src/mercury_core.h b/src/mercury_core.h index 941120f9..a38a0b54 100644 --- a/src/mercury_core.h +++ b/src/mercury_core.h @@ -1010,19 +1010,8 @@ HG_Core_event_get_wait_fd( * * \return true if there is already work to be progressed or false otherwise */ -static HG_INLINE bool -HG_Core_event_ready(hg_core_context_t *context) HG_WARN_UNUSED_RESULT; - -/** - * Used to signal when it is safe to block on the file descriptor of the - * context's wait object or if there is already work that can be progressed. - * - * \param context [IN/OUT] pointer to HG core context - * - * \return true if there is already work to be progressed or false otherwise - */ HG_PUBLIC bool -HG_Core_event_ready_loopback(hg_core_context_t *context) HG_WARN_UNUSED_RESULT; +HG_Core_event_ready(hg_core_context_t *context) HG_WARN_UNUSED_RESULT; /** * Progress communication by placing any completed RPC events into the @@ -1332,23 +1321,6 @@ HG_Core_get_output( return HG_SUCCESS; } -/*---------------------------------------------------------------------------*/ -static HG_INLINE bool -HG_Core_event_ready(hg_core_context_t *context) -{ - if (HG_Core_context_get_completion_count(context) > 0) - return true; -#ifdef NA_HAS_SM - if ((context->core_class->na_sm_class != NULL) && - !NA_Poll_try_wait( - context->core_class->na_sm_class, context->na_sm_context)) - return true; -#endif - if (!NA_Poll_try_wait(context->core_class->na_class, context->na_context)) - return true; - return HG_Core_event_ready_loopback(context); -} - #ifdef __cplusplus } #endif