Open MPI logo

Open MPI Development Mailing List Archives

  |   Home   |   Support   |   FAQ   |   all Development mailing list

Subject: [OMPI devel] RFC: Add static initializer for opal_mutex_t
From: Hjelm, Nathan T (hjelmn_at_[hidden])
Date: 2013-06-07 12:01:26


What: Add a static initializer for opal_mutex_t for both posix and solaris threads.

Why: Enables the use of opal locks that don't have to be OBJ_CONSTRUCT'ed.

When: This is a trivial addition but I would like some review/testing of the code (I don't have solaris). Setting timeout to Tuesday, June 11, 2013

diff --git a/opal/threads/mutex_unix.h b/opal/threads/mutex_unix.h
index 27528e6..28b1744 100644
--- a/opal/threads/mutex_unix.h
+++ b/opal/threads/mutex_unix.h
@@ -81,6 +81,25 @@ OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_mutex_t);
  * POSIX threads
  ************************************************************************/
 
+#if !OPAL_ENABLE_MULTI_THREADS && OPAL_ENABLE_DEBUG
+#define OPAL_MUTEX_STATIC_INIT \
+ { \
+ .super = OPAL_OBJ_STATIC_INIT(opal_object_t), \
+ .m_lock_pthread = PTHREAD_MUTEX_INITIALIZER, \
+ .m_lock_debug = 0, \
+ .m_lock_file = NULL, \
+ .m_lock_line = 0, \
+ .m_lock_atomic = 0 \
+ }
+#else
+#define OPAL_MUTEX_STATIC_INIT \
+ { \
+ .super = OPAL_OBJ_STATIC_INIT(opal_object_t), \
+ .m_lock_pthread = PTHREAD_MUTEX_INITIALIZER, \
+ .m_lock_atomic = 0 \
+ }
+#endif
+
 static inline int opal_mutex_trylock(opal_mutex_t *m)
 {
 #if OPAL_ENABLE_DEBUG
@@ -130,6 +149,25 @@ static inline void opal_mutex_unlock(opal_mutex_t *m)
  * Solaris threads
  ************************************************************************/
 
+#if !OPAL_ENABLE_MULTI_THREADS && OPAL_ENABLE_DEBUG
+#define OPAL_MUTEX_STATIC_INIT \
+ { \
+ .super = OPAL_OBJ_STATIC_INIT(opal_object_t), \
+ .m_lock_solaris = DEFAULTMUTEX, \
+ .m_lock_debug = 0, \
+ .m_lock_file = NULL, \
+ .m_lock_line = 0, \
+ .m_lock_atomic = 0 \
+ }
+#else
+#define OPAL_MUTEX_STATIC_INIT \
+ { \
+ .super = OPAL_OBJ_STATIC_INIT(opal_object_t), \
+ .m_lock_solaris = DEFAULTMUTEX, \
+ .m_lock_atomic = 0 \
+ }
+#endif
+
 
 static inline int opal_mutex_trylock(opal_mutex_t *m)
 {