Skip to content

Commit ee747c6

Browse files
authored
Merge pull request #12034 from bosilca/topic/fixes_static_initialization_of_recursive_mutexes
Avoid static initialization of recursive mutexes
2 parents 517dcba + 787dd7b commit ee747c6

File tree

4 files changed

+26
-1
lines changed

4 files changed

+26
-1
lines changed

config/opal_check_attributes.m4

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,14 @@ AC_DEFUN([OPAL_CHECK_ATTRIBUTES], [
559559
[],
560560
[])
561561

562+
_OPAL_CHECK_SPECIFIC_ATTRIBUTE([constructor],
563+
[
564+
void foo(void) __attribute__ ((__constructor__));
565+
void foo(void) { return ; }
566+
],
567+
[],
568+
[])
569+
562570
_OPAL_CHECK_SPECIFIC_ATTRIBUTE([destructor],
563571
[
564572
void foo(void) __attribute__ ((__destructor__));
@@ -631,6 +639,8 @@ AC_DEFUN([OPAL_CHECK_ATTRIBUTES], [
631639
[Whether your compiler has __attribute__ warn unused result or not])
632640
AC_DEFINE_UNQUOTED(OPAL_HAVE_ATTRIBUTE_WEAK_ALIAS, [$opal_cv___attribute__weak_alias],
633641
[Whether your compiler has __attribute__ weak alias or not])
642+
AC_DEFINE_UNQUOTED(OPAL_HAVE_ATTRIBUTE_CONSTRUCTOR, [$opal_cv___attribute__constructor],
643+
[Whether your compiler has __attribute__ constructor or not])
634644
AC_DEFINE_UNQUOTED(OPAL_HAVE_ATTRIBUTE_DESTRUCTOR, [$opal_cv___attribute__destructor],
635645
[Whether your compiler has __attribute__ destructor or not])
636646
AC_DEFINE_UNQUOTED(OPAL_HAVE_ATTRIBUTE_OPTNONE, [$opal_cv___attribute__optnone],

ompi/instance/instance.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,16 @@
5959

6060
ompi_predefined_instance_t ompi_mpi_instance_null = {{{{0}}}};
6161

62+
#if defined(OPAL_RECURSIVE_MUTEX_STATIC_INIT)
6263
static opal_recursive_mutex_t instance_lock = OPAL_RECURSIVE_MUTEX_STATIC_INIT;
64+
#elif defined(OPAL_HAVE_ATTRIBUTE_CONSTRUCTOR)
65+
static opal_recursive_mutex_t instance_lock;
66+
__opal_attribute_constructor__ static void instance_lock_init(void) {
67+
OBJ_CONSTRUCT(&instance_lock, opal_recursive_mutex_t);
68+
}
69+
#else
70+
#error "No support for recursive mutexes available on this platform.
71+
#endif /* defined(OPAL_RECURSIVE_MUTEX_STATIC_INIT) */
6372

6473
/** MPI_Init instance */
6574
ompi_instance_t *ompi_mpi_instance_default = NULL;

opal/include/opal_config_bottom.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,12 @@
229229
# define __opal_attribute_weak_alias__(a)
230230
#endif
231231

232+
#if OPAL_HAVE_ATTRIBUTE_CONSTRUCTOR
233+
# define __opal_attribute_constructor__ __attribute__((__constructor__))
234+
#else
235+
# define __opal_attribute_constructor__
236+
#endif
237+
232238
#if OPAL_HAVE_ATTRIBUTE_DESTRUCTOR
233239
# define __opal_attribute_destructor__ __attribute__((__destructor__))
234240
#else

opal/mca/btl/usnic/btl_usnic_component.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
#define OPAL_BTL_USNIC_NUM_COMPLETIONS 500
8484

8585
/* MPI_THREAD_MULTIPLE_SUPPORT */
86-
opal_recursive_mutex_t btl_usnic_lock = OPAL_RECURSIVE_MUTEX_STATIC_INIT;
86+
opal_recursive_mutex_t btl_usnic_lock; /* recursive mutexes must be dynamically initialized */
8787

8888
/* RNG buffer definition */
8989
opal_rng_buff_t opal_btl_usnic_rand_buff = {{0}};

0 commit comments

Comments
 (0)