@@ -398,12 +398,16 @@ static inline void ompi_request_wait_completion(ompi_request_t *req)
398398#endif
399399/**
400400 * Signal or mark a request as complete. If with_signal is true this will
401- * wake any thread pending on the request and ompi_request_lock should be
402- * held while calling this function. If with_signal is false, there will
403- * signal generated, and no lock required. This is a special case when
404- * the function is called from the critical path for small messages, where
405- * we know the current execution flow created the request, and is still
406- * in the _START macro.
401+ * wake any thread pending on the request. If with_signal is false, the
402+ * opposite will be true, the request will simply be marked as completed
403+ * and no effort will be made to correctly (atomically) handle the associated
404+ * synchronization primitive. This is a special case when the function
405+ * is called from the critical path for small messages, where we know
406+ * the current execution flow created the request, and no synchronized wait
407+ * has been set.
408+ * BEWARE: The error code should be set on the request prior to calling
409+ * this function, or the synchronization primitive might not be correctly
410+ * triggered.
407411 */
408412static inline int ompi_request_complete (ompi_request_t * request , bool with_signal )
409413{
@@ -412,13 +416,16 @@ static inline int ompi_request_complete(ompi_request_t* request, bool with_signa
412416 request -> req_complete_cb = NULL ;
413417 }
414418
415- if (!OPAL_ATOMIC_CMPSET_PTR (& request -> req_complete , REQUEST_PENDING , REQUEST_COMPLETED )) {
416- ompi_wait_sync_t * tmp_sync = (ompi_wait_sync_t * ) OPAL_ATOMIC_SWP_PTR (& request -> req_complete ,
417- REQUEST_COMPLETED );
418- /* In the case where another thread concurrently changed the request to REQUEST_PENDING */
419- if ( REQUEST_PENDING != tmp_sync )
420- wait_sync_update (tmp_sync , 1 , request -> req_status .MPI_ERROR );
421- }
419+ if ( OPAL_LIKELY (with_signal ) ) {
420+ if (!OPAL_ATOMIC_CMPSET_PTR (& request -> req_complete , REQUEST_PENDING , REQUEST_COMPLETED )) {
421+ ompi_wait_sync_t * tmp_sync = (ompi_wait_sync_t * ) OPAL_ATOMIC_SWP_PTR (& request -> req_complete ,
422+ REQUEST_COMPLETED );
423+ /* In the case where another thread concurrently changed the request to REQUEST_PENDING */
424+ if ( REQUEST_PENDING != tmp_sync )
425+ wait_sync_update (tmp_sync , 1 , request -> req_status .MPI_ERROR );
426+ }
427+ } else
428+ request -> req_complete = REQUEST_COMPLETED ;
422429
423430 if ( OPAL_UNLIKELY (MPI_SUCCESS != request -> req_status .MPI_ERROR ) ) {
424431 ompi_request_failed ++ ;
0 commit comments