Skip to content

Commit

Permalink
Add support for __constructor__
Browse files Browse the repository at this point in the history
The only remaining statically initialized recursive mutex has now
support for the constructor attribute.

Signed-off-by: George Bosilca <[email protected]>
  • Loading branch information
bosilca committed Oct 30, 2023
1 parent ad4c825 commit 787dd7b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
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
6 changes: 4 additions & 2 deletions ompi/instance/instance.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,13 @@ 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;
#else
#elif defined(OPAL_HAVE_ATTRIBUTE_CONSTRUCTOR)
static opal_recursive_mutex_t instance_lock;
__attribute__((__constructor__)) static void instance_lock_init(void) {
__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 */
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

0 comments on commit 787dd7b

Please sign in to comment.