When debugging code is turned on with --enable-debug, try to use error checking
mutexes instead of fast mutexes. If an error occurs, a message will be printed, and abort() will be called. This commit was SVN r8671.
Этот коммит содержится в:
родитель
c2ee847184
Коммит
9310fd6f85
@ -635,6 +635,33 @@ OMPI_INTL_POSIX_THREADS_SPECIAL_FLAGS
|
||||
# Try the normal linking methods (that's no fun)
|
||||
OMPI_INTL_POSIX_THREADS_LIBS
|
||||
|
||||
|
||||
#
|
||||
# check to see if we can set error checking mutexes
|
||||
#
|
||||
|
||||
# LinuxThreads
|
||||
AC_MSG_CHECKING([for PTHREAD_MUTEX_ERRORCHECK_NP])
|
||||
AC_LINK_IFELSE(
|
||||
[AC_LANG_PROGRAM(
|
||||
[[#include <pthread.h>]],
|
||||
[[pthread_mutexattr_settype(NULL, PTHREAD_MUTEX_ERRORCHECK_NP);]])],
|
||||
[result="yes" defval=1], [result="no" defval=0])
|
||||
AC_MSG_RESULT([$result])
|
||||
AC_DEFINE_UNQUOTED([OMPI_HAVE_PTHREAD_MUTEX_ERRORCHECK_NP], [$defval],
|
||||
[If PTHREADS implementation supports PTHREAD_MUTEX_ERRORCHECK_NP])
|
||||
|
||||
# Mac OS X
|
||||
AC_MSG_CHECKING([for PTHREAD_MUTEX_ERRORCHECK])
|
||||
AC_LINK_IFELSE(
|
||||
[AC_LANG_PROGRAM(
|
||||
[[#include <pthread.h>]],
|
||||
[[pthread_mutexattr_settype(NULL, PTHREAD_MUTEX_ERRORCHECK);]])],
|
||||
[result="yes" defval=1], [result="no" defval=0])
|
||||
AC_MSG_RESULT([$result])
|
||||
AC_DEFINE_UNQUOTED([OMPI_HAVE_PTHREAD_MUTEX_ERRORCHECK], [$defval],
|
||||
[If PTHREADS implementation supports PTHREAD_MUTEX_ERRORCHECK])
|
||||
|
||||
CFLAGS="$orig_CFLAGS"
|
||||
FFLAGS="$orig_FFLAGS"
|
||||
CXXFLAGS="$orig_CXXFLAGS"
|
||||
|
@ -44,8 +44,25 @@ static void opal_mutex_destruct(opal_mutex_t *m)
|
||||
static void opal_mutex_construct(opal_mutex_t *m)
|
||||
{
|
||||
#if OMPI_HAVE_POSIX_THREADS
|
||||
pthread_mutex_init(&m->m_lock_pthread, 0);
|
||||
pthread_mutexattr_t attr;
|
||||
pthread_mutexattr_init(&attr);
|
||||
|
||||
#if OMPI_ENABLE_DEBUG && OMPI_HAVE_PTHREAD_MUTEX_ERRORCHECK_NP
|
||||
/* set type to ERRORCHECK so that we catch recursive locks */
|
||||
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK_NP);
|
||||
#elif OMPI_ENABLE_DEBUG && OMPI_HAVE_PTHREAD_MUTEX_ERRORCHECK
|
||||
/* set type to ERRORCHECK so that we catch recursive locks */
|
||||
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK);
|
||||
#endif
|
||||
|
||||
pthread_mutex_init(&m->m_lock_pthread, &attr);
|
||||
pthread_mutexattr_destroy(&attr);
|
||||
#endif /* OMPI_HAVE_POSIX_THREADS */
|
||||
|
||||
#if OPAL_HAVE_SOLARIS_THREADS
|
||||
mutex_init(&m->m_lock_solaris, USYNC_THREAD, NULL);
|
||||
#endif
|
||||
|
||||
#if OPAL_HAVE_ATOMIC_SPINLOCKS
|
||||
opal_atomic_init( &m->m_lock_atomic, OPAL_ATOMIC_UNLOCKED );
|
||||
#endif
|
||||
|
@ -22,7 +22,7 @@
|
||||
/**
|
||||
* @file:
|
||||
*
|
||||
* Mutual exclusion functions: Windows implementation.
|
||||
* Mutual exclusion functions: Unix implementation.
|
||||
*
|
||||
* Functions for locking of critical sections.
|
||||
*
|
||||
@ -35,6 +35,8 @@
|
||||
#ifdef HAVE_PTHREAD_H
|
||||
#include <pthread.h>
|
||||
#endif
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
#include "opal/class/opal_object.h"
|
||||
@ -47,6 +49,9 @@ struct opal_mutex_t {
|
||||
opal_object_t super;
|
||||
#if OMPI_HAVE_POSIX_THREADS
|
||||
pthread_mutex_t m_lock_pthread;
|
||||
#endif
|
||||
#if OMPI_HAVE_SOLARIS_THREADS
|
||||
mutex_t m_lock_solaris;
|
||||
#endif
|
||||
opal_atomic_lock_t m_lock_atomic;
|
||||
};
|
||||
@ -54,89 +59,85 @@ struct opal_mutex_t {
|
||||
OMPI_DECLSPEC OBJ_CLASS_DECLARATION(opal_mutex_t);
|
||||
|
||||
|
||||
#if OPAL_HAVE_ATOMIC_SPINLOCKS && OMPI_HAVE_POSIX_THREADS
|
||||
|
||||
/*
|
||||
* opal_mutex_* implemented using pthreads
|
||||
* opal_mutex_atomic_* implemented using atomic operations
|
||||
*/
|
||||
/************************************************************************
|
||||
*
|
||||
* mutex operations (non-atomic versions)
|
||||
*
|
||||
************************************************************************/
|
||||
|
||||
#if OMPI_HAVE_POSIX_THREADS
|
||||
|
||||
/************************************************************************
|
||||
* POSIX threads
|
||||
************************************************************************/
|
||||
|
||||
static inline int opal_mutex_trylock(opal_mutex_t *m)
|
||||
{
|
||||
#if OMPI_ENABLE_DEBUG
|
||||
int ret = pthread_mutex_trylock(&m->m_lock_pthread);
|
||||
if (ret == EDEADLK) {
|
||||
errno = ret;
|
||||
perror("opal_mutex_trylock()");
|
||||
abort();
|
||||
}
|
||||
return ret;
|
||||
#else
|
||||
return pthread_mutex_trylock(&m->m_lock_pthread);
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline void opal_mutex_lock(opal_mutex_t *m)
|
||||
{
|
||||
pthread_mutex_lock(&m->m_lock_pthread);
|
||||
int ret = pthread_mutex_lock(&m->m_lock_pthread);
|
||||
#if OMPI_ENABLE_DEBUG
|
||||
if (ret == EDEADLK) {
|
||||
errno = ret;
|
||||
perror("opal_mutex_lock()");
|
||||
abort();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline void opal_mutex_unlock(opal_mutex_t *m)
|
||||
{
|
||||
pthread_mutex_unlock(&m->m_lock_pthread);
|
||||
int ret = pthread_mutex_unlock(&m->m_lock_pthread);
|
||||
#if OMPI_ENABLE_DEBUG
|
||||
if (ret == EPERM) {
|
||||
errno = ret;
|
||||
perror("opal_mutex_unlock");
|
||||
abort();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#elif OMPI_HAVE_SOLARIS_THREADS
|
||||
|
||||
static inline void opal_mutex_atomic_lock(opal_mutex_t *m)
|
||||
{
|
||||
opal_atomic_lock(&m->m_lock_atomic);
|
||||
}
|
||||
/************************************************************************
|
||||
* Solaris threads
|
||||
************************************************************************/
|
||||
|
||||
static inline int opal_mutex_atomic_trylock(opal_mutex_t *m)
|
||||
{
|
||||
return opal_atomic_trylock(&m->m_lock_atomic);
|
||||
}
|
||||
|
||||
static inline void opal_mutex_atomic_unlock(opal_mutex_t *m)
|
||||
{
|
||||
opal_atomic_unlock(&m->m_lock_atomic);
|
||||
}
|
||||
|
||||
|
||||
#elif OMPI_HAVE_POSIX_THREADS
|
||||
|
||||
/*
|
||||
* opal_mutex_* and opal_mutex_atomic_* implemented using pthreads
|
||||
*/
|
||||
|
||||
static inline int opal_mutex_trylock(opal_mutex_t *m)
|
||||
{
|
||||
return pthread_mutex_trylock(&m->m_lock_pthread);
|
||||
return mutex_trylock(&m->m_lock_solaris);
|
||||
}
|
||||
|
||||
static inline void opal_mutex_lock(opal_mutex_t *m)
|
||||
{
|
||||
pthread_mutex_lock(&m->m_lock_pthread);
|
||||
mutex_lock(&m->m_lock_solaris);
|
||||
}
|
||||
|
||||
static inline void opal_mutex_unlock(opal_mutex_t *m)
|
||||
{
|
||||
pthread_mutex_unlock(&m->m_lock_pthread);
|
||||
mutex_unlock(&m->m_lock_solaris);
|
||||
}
|
||||
|
||||
|
||||
static inline int opal_mutex_atomic_trylock(opal_mutex_t *m)
|
||||
{
|
||||
return opal_mutex_trylock(m);
|
||||
}
|
||||
|
||||
static inline void opal_mutex_atomic_lock(opal_mutex_t *m)
|
||||
{
|
||||
opal_mutex_lock(m);
|
||||
}
|
||||
|
||||
static inline void opal_mutex_atomic_unlock(opal_mutex_t *m)
|
||||
{
|
||||
opal_mutex_unlock(m);
|
||||
}
|
||||
|
||||
|
||||
#elif OPAL_HAVE_ATOMIC_SPINLOCKS
|
||||
|
||||
/*
|
||||
* opal_mutex_* and opal_mutex_atomic_* implemented using atomic
|
||||
* operations
|
||||
*/
|
||||
/************************************************************************
|
||||
* Spin Locks
|
||||
************************************************************************/
|
||||
|
||||
static inline int opal_mutex_trylock(opal_mutex_t *m)
|
||||
{
|
||||
@ -153,29 +154,63 @@ static inline void opal_mutex_unlock(opal_mutex_t *m)
|
||||
opal_atomic_unlock(&m->m_lock_atomic);
|
||||
}
|
||||
|
||||
|
||||
static inline int opal_mutex_atomic_trylock(opal_mutex_t *m)
|
||||
{
|
||||
return opal_mutex_trylock(m);
|
||||
}
|
||||
|
||||
static inline void opal_mutex_atomic_lock(opal_mutex_t *m)
|
||||
{
|
||||
opal_mutex_lock(m);
|
||||
}
|
||||
|
||||
static inline void opal_mutex_atomic_unlock(opal_mutex_t *m)
|
||||
{
|
||||
opal_mutex_unlock(m);
|
||||
}
|
||||
|
||||
|
||||
#else
|
||||
|
||||
#error No mutex definition
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/************************************************************************
|
||||
*
|
||||
* mutex operations (atomic versions)
|
||||
*
|
||||
************************************************************************/
|
||||
|
||||
#if OPAL_HAVE_ATOMIC_SPINLOCKS
|
||||
|
||||
/************************************************************************
|
||||
* Spin Locks
|
||||
************************************************************************/
|
||||
|
||||
static inline int opal_mutex_atomic_trylock(opal_mutex_t *m)
|
||||
{
|
||||
return opal_atomic_trylock(&m->m_lock_atomic);
|
||||
}
|
||||
|
||||
static inline void opal_mutex_atomic_lock(opal_mutex_t *m)
|
||||
{
|
||||
opal_atomic_lock(&m->m_lock_atomic);
|
||||
}
|
||||
|
||||
static inline void opal_mutex_atomic_unlock(opal_mutex_t *m)
|
||||
{
|
||||
opal_atomic_unlock(&m->m_lock_atomic);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
/************************************************************************
|
||||
* Stanard locking
|
||||
************************************************************************/
|
||||
|
||||
static inline int opal_mutex_atomic_trylock(opal_mutex_t *m)
|
||||
{
|
||||
return opal_mutex_trylock(m);
|
||||
}
|
||||
|
||||
static inline void opal_mutex_atomic_lock(opal_mutex_t *m)
|
||||
{
|
||||
opal_mutex_lock(m);
|
||||
}
|
||||
|
||||
static inline void opal_mutex_atomic_unlock(opal_mutex_t *m)
|
||||
{
|
||||
opal_mutex_unlock(m);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(c_plusplus) || defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
Загрузка…
Ссылка в новой задаче
Block a user