Skip to content

Commit 787dd7b

Browse files
committed
Add support for __constructor__
The only remaining statically initialized recursive mutex has now support for the constructor attribute. Signed-off-by: George Bosilca <bosilca@icl.utk.edu>
1 parent ad4c825 commit 787dd7b

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
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: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,13 @@ ompi_predefined_instance_t ompi_mpi_instance_null = {{{{0}}}};
6161

6262
#if defined(OPAL_RECURSIVE_MUTEX_STATIC_INIT)
6363
static opal_recursive_mutex_t instance_lock = OPAL_RECURSIVE_MUTEX_STATIC_INIT;
64-
#else
64+
#elif defined(OPAL_HAVE_ATTRIBUTE_CONSTRUCTOR)
6565
static opal_recursive_mutex_t instance_lock;
66-
__attribute__((__constructor__)) static void instance_lock_init(void) {
66+
__opal_attribute_constructor__ static void instance_lock_init(void) {
6767
OBJ_CONSTRUCT(&instance_lock, opal_recursive_mutex_t);
6868
}
69+
#else
70+
#error "No support for recursive mutexes available on this platform.
6971
#endif /* defined(OPAL_RECURSIVE_MUTEX_STATIC_INIT) */
7072

7173
/** MPI_Init instance */

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

0 commit comments

Comments
 (0)