Skip to content

Commit bab0bd7

Browse files
authored
Merge pull request #10350 from devreal/predefined-attributes-cycle
Don't retain/release the ompi instance for predefined attributes
2 parents 99e279f + aed5b80 commit bab0bd7

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

ompi/attribute/attribute.c

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -679,17 +679,22 @@ int ompi_attr_create_keyval(ompi_attribute_type_t type,
679679
{
680680
ompi_attribute_fortran_ptr_t es_tmp;
681681
int rc;
682-
683-
rc = ompi_mpi_instance_retain ();
684-
if (OPAL_UNLIKELY(OMPI_SUCCESS != rc)) {
685-
return rc;
682+
bool is_predefined = flags & OMPI_KEYVAL_PREDEFINED;
683+
684+
/* Predefined attributes are created as part of the instance creation,
685+
* so do not retain the instance to avoid a circular dependency */
686+
if (!is_predefined) {
687+
rc = ompi_mpi_instance_retain ();
688+
if (OPAL_UNLIKELY(OMPI_SUCCESS != rc)) {
689+
return rc;
690+
}
686691
}
687692

688693
es_tmp.c_ptr = extra_state;
689694
rc = ompi_attr_create_keyval_impl(type, copy_attr_fn, delete_attr_fn,
690695
key, &es_tmp, flags,
691696
bindings_extra_state);
692-
if (OPAL_UNLIKELY(OMPI_SUCCESS != rc)) {
697+
if (OPAL_UNLIKELY(OMPI_SUCCESS != rc) && !is_predefined) {
693698
ompi_mpi_instance_release ();
694699
}
695700

@@ -773,8 +778,12 @@ int ompi_attr_free_keyval(ompi_attribute_type_t type, int *key,
773778
opal_atomic_wmb();
774779
OPAL_THREAD_UNLOCK(&attribute_lock);
775780

776-
/* balance out retain in keyval_create */
777-
ompi_mpi_instance_release ();
781+
/* balance out retain in keyval_create
782+
* predefined attributes do not retain the instance so do not release it either
783+
*/
784+
if (!predefined) {
785+
ompi_mpi_instance_release ();
786+
}
778787

779788
return MPI_SUCCESS;
780789
}

0 commit comments

Comments
 (0)