opal: add recursive mutex
This new class is the same as the opal_mutex_t class but has a different constructor. This constructor adds the recursive flag to the mutex attributes for the lock. This class can be used where there may be re-enty into the lock from within the same thread. Signed-off-by: Nathan Hjelm <hjelmn@lanl.gov>
Этот коммит содержится в:
родитель
b4fcd3897e
Коммит
54998e5745
@ -72,3 +72,29 @@ OBJ_CLASS_INSTANCE(opal_mutex_t,
|
||||
opal_object_t,
|
||||
opal_mutex_construct,
|
||||
opal_mutex_destruct);
|
||||
|
||||
static void opal_recursive_mutex_construct(opal_recursive_mutex_t *m)
|
||||
{
|
||||
pthread_mutexattr_t attr;
|
||||
pthread_mutexattr_init(&attr);
|
||||
|
||||
#if OPAL_ENABLE_DEBUG
|
||||
m->m_lock_debug = 0;
|
||||
m->m_lock_file = NULL;
|
||||
m->m_lock_line = 0;
|
||||
#endif
|
||||
|
||||
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
|
||||
|
||||
pthread_mutex_init(&m->m_lock_pthread, &attr);
|
||||
pthread_mutexattr_destroy(&attr);
|
||||
|
||||
#if OPAL_HAVE_ATOMIC_SPINLOCKS
|
||||
opal_atomic_init( &m->m_lock_atomic, OPAL_ATOMIC_UNLOCKED );
|
||||
#endif
|
||||
}
|
||||
|
||||
OBJ_CLASS_INSTANCE(opal_recursive_mutex_t,
|
||||
opal_object_t,
|
||||
opal_recursive_mutex_construct,
|
||||
opal_mutex_destruct);
|
||||
|
@ -50,7 +50,7 @@ OPAL_DECLSPEC extern bool opal_uses_threads;
|
||||
* Opaque mutex object
|
||||
*/
|
||||
typedef struct opal_mutex_t opal_mutex_t;
|
||||
|
||||
typedef struct opal_mutex_t opal_recursive_mutex_t;
|
||||
|
||||
/**
|
||||
* Try to acquire a mutex.
|
||||
|
@ -61,6 +61,7 @@ struct opal_mutex_t {
|
||||
opal_atomic_lock_t m_lock_atomic;
|
||||
};
|
||||
OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_mutex_t);
|
||||
OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_recursive_mutex_t);
|
||||
|
||||
/************************************************************************
|
||||
*
|
||||
|
Загрузка…
Ссылка в новой задаче
Block a user