1
1

opal/mutex: add static mutex initializers

Signed-off-by: Nathan Hjelm <hjelmn@lanl.gov>
Этот коммит содержится в:
Nathan Hjelm 2015-10-14 15:43:13 -06:00
родитель caa6b2ef00
Коммит 039c7dbcd6
2 изменённых файлов: 63 добавлений и 3 удалений

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

@ -168,9 +168,20 @@ extern int opal_class_init_epoch;
* @param NAME Name of the class to initialize * @param NAME Name of the class to initialize
*/ */
#if OPAL_ENABLE_DEBUG #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 #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 #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 * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
* University Research and Technology * University Research and Technology
@ -9,7 +10,7 @@
* University of Stuttgart. All rights reserved. * University of Stuttgart. All rights reserved.
* Copyright (c) 2004-2005 The Regents of the University of California. * Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved. * 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. * reserved.
* Copyright (c) 2015 Research Organization for Information Science * Copyright (c) 2015 Research Organization for Information Science
* and Technology (RIST). All rights reserved. * 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_mutex_t);
OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_recursive_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) * mutex operations (non-atomic versions)