Skip to content

opal static mutex initializers #1026

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
Oct 15, 2015
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: 0 additions & 10 deletions ompi/mpi/tool/init_thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,8 @@ extern volatile int32_t initted;

int MPI_T_init_thread (int required, int *provided)
{
static volatile int32_t first_init = 1;
int rc = MPI_SUCCESS;

if (opal_atomic_cmpset (&first_init, 1, 0) == 1) {
OBJ_CONSTRUCT(&mpit_big_lock, opal_mutex_t);
initted = 1;
}

while (!initted) {
usleep (10);
}

mpit_lock ();

do {
Expand Down
11 changes: 3 additions & 8 deletions ompi/mpi/tool/mpit_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,18 @@

#include "ompi/mpi/tool/mpit-internal.h"

opal_mutex_t mpit_big_lock = {{0}};
opal_mutex_t mpit_big_lock = OPAL_MUTEX_STATIC_INIT;

volatile uint32_t mpit_init_count = 0;
volatile int32_t initted = 0;

void mpit_lock (void)
{
if (initted) {
opal_mutex_lock (&mpit_big_lock);
}
opal_mutex_lock (&mpit_big_lock);
}

void mpit_unlock (void)
{
if (initted) {
opal_mutex_unlock (&mpit_big_lock);
}
opal_mutex_unlock (&mpit_big_lock);
}

int ompit_var_type_to_datatype (mca_base_var_type_t type, MPI_Datatype *datatype)
Expand Down
15 changes: 13 additions & 2 deletions opal/class/opal_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,20 @@ extern int opal_class_init_epoch;
* @param NAME Name of the class to initialize
*/
#if OPAL_ENABLE_DEBUG
#define OPAL_OBJ_STATIC_INIT(BASE_CLASS) { OPAL_OBJ_MAGIC_ID, OBJ_CLASS(BASE_CLASS), 1, __FILE__, __LINE__ }
#define OPAL_OBJ_STATIC_INIT(BASE_CLASS) \
{ \
.obj_magic_id = OPAL_OBJ_MAGIC_ID, \
.obj_class = OBJ_CLASS(BASE_CLASS), \
.obj_reference_count = 1, \
.cls_init_file_name = __FILE__, \
.cls_init_lineno = __LINE__, \
}
#else
#define OPAL_OBJ_STATIC_INIT(BASE_CLASS) { OBJ_CLASS(BASE_CLASS), 1 }
#define OPAL_OBJ_STATIC_INIT(BASE_CLASS) \
{ \
.obj_class = OBJ_CLASS(BASE_CLASS), \
.obj_reference_count = 1, \
}
#endif

/**
Expand Down
51 changes: 50 additions & 1 deletion opal/threads/mutex_unix.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
/*
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
* University Research and Technology
Expand All @@ -9,7 +10,7 @@
* University of Stuttgart. All rights reserved.
* Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 2007 Los Alamos National Security, LLC. All rights
* Copyright (c) 2007-2015 Los Alamos National Security, LLC. All rights
* reserved.
* Copyright (c) 2015 Research Organization for Information Science
* and Technology (RIST). All rights reserved.
Expand Down Expand Up @@ -63,6 +64,54 @@ struct opal_mutex_t {
OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_mutex_t);
OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_recursive_mutex_t);

#if defined(PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP)
#define OPAL_PTHREAD_RECURSIVE_MUTEX_INITIALIZER PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
#elif defined(PTHREAD_RECURSIVE_MUTEX_INITIALIZER)
#define OPAL_PTHREAD_RECURSIVE_MUTEX_INITIALIZER PTHREAD_RECURSIVE_MUTEX_INITIALIZER
#endif

#if OPAL_ENABLE_DEBUG
#define OPAL_MUTEX_STATIC_INIT \
{ \
.super = OPAL_OBJ_STATIC_INIT(opal_mutex_t), \
.m_lock_pthread = PTHREAD_MUTEX_INITIALIZER, \
.m_lock_debug = 0, \
.m_lock_file = NULL, \
.m_lock_line = 0, \
.m_lock_atomic = { .u = { .lock = OPAL_ATOMIC_UNLOCKED } }, \
}
#else
#define OPAL_MUTEX_STATIC_INIT \
{ \
.super = OPAL_OBJ_STATIC_INIT(opal_mutex_t), \
.m_lock_pthread = PTHREAD_MUTEX_INITIALIZER, \
.m_lock_atomic = { .u = { .lock = OPAL_ATOMIC_UNLOCKED } }, \
}
#endif

#if defined(OPAL_PTHREAD_RECURSIVE_MUTEX_INITIALIZER)

#if OPAL_ENABLE_DEBUG
#define OPAL_RECURSIVE_MUTEX_STATIC_INIT \
{ \
.super = OPAL_OBJ_STATIC_INIT(opal_mutex_t), \
.m_lock_pthread = OPAL_PTHREAD_RECURSIVE_MUTEX_INITIALIZER, \
.m_lock_debug = 0, \
.m_lock_file = NULL, \
.m_lock_line = 0, \
.m_lock_atomic = { .u = { .lock = OPAL_ATOMIC_UNLOCKED } }, \
}
#else
#define OPAL_RECURSIVE_MUTEX_STATIC_INIT \
{ \
.super = OPAL_OBJ_STATIC_INIT(opal_mutex_t), \
.m_lock_pthread = OPAL_PTHREAD_RECURSIVE_MUTEX_INITIALIZER, \
.m_lock_atomic = { .u = { .lock = OPAL_ATOMIC_UNLOCKED } }, \
}
#endif

#endif

/************************************************************************
*
* mutex operations (non-atomic versions)
Expand Down