Function ucp_worker_arm

Source
pub unsafe extern "C" fn ucp_worker_arm(
    worker: ucp_worker_h,
) -> ucs_status_t
Expand description

@ingroup UCP_WAKEUP @brief Turn on event notification for the next event.

This routine needs to be called before waiting on each notification on this worker, so will typically be called once the processing of the previous event is over, as part of the wake-up mechanism.

The worker must be armed before waiting on an event (must be re-armed after it has been signaled for re-use) with @ref ucp_worker_arm. The events triggering a signal of the file descriptor from @ref ucp_worker_get_efd depend on the interfaces used by the worker and defined in the transport layer, and typically represent a request completion or newly available resources. It can also be triggered by calling @ref ucp_worker_signal .

The file descriptor is guaranteed to become signaled only if new communication events occur on the @a worker. Therefore one must drain all existing events before waiting on the file descriptor. This can be achieved by calling @ref ucp_worker_progress repeatedly until it returns 0.

@code {.c} void application_initialization() { // should be called once in application init flow and before // process_communication() is used … status = ucp_worker_get_efd(worker, &fd); … }

void process_communication() { // should be called every time need to wait for some condition such as // ucp request completion in sleep mode.

for (;;) {
    // check for stop condition as long as progress is made
    if (check_for_events()) {
         break;
    } else if (ucp_worker_progress(worker)) {
         continue;                 // some progress happened but condition not met
    }

    // arm the worker and clean-up fd
    status = ucp_worker_arm(worker);
    if (UCS_OK == status) {
        poll(&fds, nfds, timeout);  // wait for events (sleep mode)
    } else if (UCS_ERR_BUSY == status) {
        continue;                   // could not arm, need to progress more
    } else {
        abort();
    }
}

} @endcode

@note UCP @ref ucp_feature “features” have to be triggered with @ref UCP_FEATURE_WAKEUP to select proper transport

@param [in] worker Worker of notified events.

@return ::UCS_OK The operation completed successfully. File descriptor will be signaled by new events. @return ::UCS_ERR_BUSY There are unprocessed events which prevent the file descriptor from being armed. These events should be removed by calling @ref ucp_worker_progress(). The operation is not completed. File descriptor will not be signaled by new events. @return @ref ucs_status_t “Other” different error codes in case of issues.