Skip to content

V5.0.x: Avoid static initialization of recursive mutexes #12057

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions config/opal_check_attributes.m4
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,14 @@ AC_DEFUN([OPAL_CHECK_ATTRIBUTES], [
[],
[])

_OPAL_CHECK_SPECIFIC_ATTRIBUTE([constructor],
[
void foo(void) __attribute__ ((__constructor__));
void foo(void) { return ; }
],
[],
[])

_OPAL_CHECK_SPECIFIC_ATTRIBUTE([destructor],
[
void foo(void) __attribute__ ((__destructor__));
Expand Down Expand Up @@ -631,6 +639,8 @@ AC_DEFUN([OPAL_CHECK_ATTRIBUTES], [
[Whether your compiler has __attribute__ warn unused result or not])
AC_DEFINE_UNQUOTED(OPAL_HAVE_ATTRIBUTE_WEAK_ALIAS, [$opal_cv___attribute__weak_alias],
[Whether your compiler has __attribute__ weak alias or not])
AC_DEFINE_UNQUOTED(OPAL_HAVE_ATTRIBUTE_CONSTRUCTOR, [$opal_cv___attribute__constructor],
[Whether your compiler has __attribute__ constructor or not])
AC_DEFINE_UNQUOTED(OPAL_HAVE_ATTRIBUTE_DESTRUCTOR, [$opal_cv___attribute__destructor],
[Whether your compiler has __attribute__ destructor or not])
AC_DEFINE_UNQUOTED(OPAL_HAVE_ATTRIBUTE_OPTNONE, [$opal_cv___attribute__optnone],
Expand Down
9 changes: 9 additions & 0 deletions ompi/instance/instance.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,16 @@

ompi_predefined_instance_t ompi_mpi_instance_null = {{{{0}}}};

#if defined(OPAL_RECURSIVE_MUTEX_STATIC_INIT)
static opal_recursive_mutex_t instance_lock = OPAL_RECURSIVE_MUTEX_STATIC_INIT;
#elif defined(OPAL_HAVE_ATTRIBUTE_CONSTRUCTOR)
static opal_recursive_mutex_t instance_lock;
__opal_attribute_constructor__ static void instance_lock_init(void) {
OBJ_CONSTRUCT(&instance_lock, opal_recursive_mutex_t);
}
#else
#error "No support for recursive mutexes available on this platform.
#endif /* defined(OPAL_RECURSIVE_MUTEX_STATIC_INIT) */

/** MPI_Init instance */
ompi_instance_t *ompi_mpi_instance_default = NULL;
Expand Down
6 changes: 6 additions & 0 deletions opal/include/opal_config_bottom.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,12 @@
# define __opal_attribute_weak_alias__(a)
#endif

#if OPAL_HAVE_ATTRIBUTE_CONSTRUCTOR
# define __opal_attribute_constructor__ __attribute__((__constructor__))
#else
# define __opal_attribute_constructor__
#endif

#if OPAL_HAVE_ATTRIBUTE_DESTRUCTOR
# define __opal_attribute_destructor__ __attribute__((__destructor__))
#else
Expand Down
2 changes: 1 addition & 1 deletion opal/mca/btl/usnic/btl_usnic_component.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
#define OPAL_BTL_USNIC_NUM_COMPLETIONS 500

/* MPI_THREAD_MULTIPLE_SUPPORT */
opal_recursive_mutex_t btl_usnic_lock = OPAL_RECURSIVE_MUTEX_STATIC_INIT;
opal_recursive_mutex_t btl_usnic_lock; /* recursive mutexes must be dynamically initialized */

/* RNG buffer definition */
opal_rng_buff_t opal_btl_usnic_rand_buff = {{0}};
Expand Down