From 039c7dbcd6bd9d2915097cdb2dcb747bc382c356 Mon Sep 17 00:00:00 2001 From: Nathan Hjelm Date: Wed, 14 Oct 2015 15:43:13 -0600 Subject: [PATCH] opal/mutex: add static mutex initializers Signed-off-by: Nathan Hjelm --- opal/class/opal_object.h | 15 ++++++++++-- opal/threads/mutex_unix.h | 51 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 63 insertions(+), 3 deletions(-) diff --git a/opal/class/opal_object.h b/opal/class/opal_object.h index 7de1c9f5d0..f5811ff4e4 100644 --- a/opal/class/opal_object.h +++ b/opal/class/opal_object.h @@ -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 /** diff --git a/opal/threads/mutex_unix.h b/opal/threads/mutex_unix.h index d159285d8e..a2de825928 100644 --- a/opal/threads/mutex_unix.h +++ b/opal/threads/mutex_unix.h @@ -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)