1
1

Merge pull request #1026 from hjelmn/static_mutex

opal static mutex initializers
Этот коммит содержится в:
Jeff Squyres 2015-10-14 22:10:51 -04:00
родитель a7e7ecd42d 7f7ff8d851
Коммит aceb1ebb47
4 изменённых файлов: 66 добавлений и 21 удалений

Просмотреть файл

@ -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 {

Просмотреть файл

@ -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)

Просмотреть файл

@ -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
/**

Просмотреть файл

@ -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
@ -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.
@ -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)