Skip to content

Commit 92389c3

Browse files
authored
Merge pull request #8500 from janciesko/opal_recursive_mutex_t_2
Add opal_recursive_mutex_t support to qthreads
2 parents 6d58d84 + 8c499a3 commit 92389c3

File tree

2 files changed

+43
-12
lines changed

2 files changed

+43
-12
lines changed

opal/mca/threads/qthreads/threads_qthreads_mutex.c

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525

2626
#include "opal_config.h"
2727

28-
#include "opal/constants.h"
2928
#include "opal/mca/threads/mutex.h"
29+
#include "opal/constants.h"
3030

3131
/*
3232
* Wait and see if some upper layer wants to use threads, if support
@@ -36,23 +36,36 @@ bool opal_uses_threads = false;
3636

3737
static void opal_mutex_construct(opal_mutex_t *m)
3838
{
39-
opal_threads_ensure_init_qthreads();
40-
opal_mutex_create(m);
39+
opal_mutex_create(m);
4140
}
4241

4342
static void opal_mutex_destruct(opal_mutex_t *m)
4443
{
4544
}
4645

47-
OBJ_CLASS_INSTANCE(opal_mutex_t, opal_object_t, opal_mutex_construct, opal_mutex_destruct);
46+
static void opal_recursive_mutex_construct(opal_mutex_t *m)
47+
{
48+
opal_mutex_recursive_create(m);
49+
}
4850

49-
static void opal_recursive_mutex_construct(opal_recursive_mutex_t *m)
51+
static void opal_recursive_mutex_destruct(opal_mutex_t *m)
5052
{
5153
}
5254

53-
OBJ_CLASS_INSTANCE(opal_recursive_mutex_t, opal_object_t, opal_recursive_mutex_construct,
55+
OBJ_CLASS_INSTANCE(opal_mutex_t,
56+
opal_object_t,
57+
opal_mutex_construct,
5458
opal_mutex_destruct);
5559

60+
static void opal_recursive_mutex_construct(opal_recursive_mutex_t *m)
61+
{
62+
}
63+
64+
OBJ_CLASS_INSTANCE(opal_recursive_mutex_t,
65+
opal_object_t,
66+
opal_recursive_mutex_construct,
67+
opal_recursive_mutex_destruct);
68+
5669
int opal_cond_init(opal_cond_t *cond)
5770
{
5871
opal_atomic_lock_init(&cond->m_lock, 0);
@@ -63,7 +76,7 @@ int opal_cond_init(opal_cond_t *cond)
6376

6477
typedef struct {
6578
int m_signaled;
66-
void *m_prev;
79+
void * m_prev;
6780
} cond_waiter_t;
6881

6982
int opal_cond_wait(opal_cond_t *cond, opal_mutex_t *lock)
@@ -74,11 +87,11 @@ int opal_cond_wait(opal_cond_t *cond, opal_mutex_t *lock)
7487
opal_atomic_lock(&cond->m_lock);
7588
cond_waiter_t waiter = {0, NULL};
7689
if (NULL == cond->m_waiter_head) {
77-
cond->m_waiter_tail = (void *) &waiter;
90+
cond->m_waiter_tail = (void *)&waiter;
7891
} else {
79-
((cond_waiter_t *) cond->m_waiter_head)->m_prev = (void *) &waiter;
92+
((cond_waiter_t *)cond->m_waiter_head)->m_prev = (void *)&waiter;
8093
}
81-
cond->m_waiter_head = (void *) &waiter;
94+
cond->m_waiter_head = (void *)&waiter;
8295
opal_atomic_unlock(&cond->m_lock);
8396

8497
while (1) {
@@ -101,7 +114,7 @@ int opal_cond_broadcast(opal_cond_t *cond)
101114
{
102115
opal_atomic_lock(&cond->m_lock);
103116
while (NULL != cond->m_waiter_tail) {
104-
cond_waiter_t *p_cur_tail = (cond_waiter_t *) cond->m_waiter_tail;
117+
cond_waiter_t *p_cur_tail = (cond_waiter_t *)cond->m_waiter_tail;
105118
cond->m_waiter_tail = p_cur_tail->m_prev;
106119
/* Awaken one of threads in a FIFO manner. */
107120
p_cur_tail->m_signaled = 1;
@@ -116,7 +129,7 @@ int opal_cond_signal(opal_cond_t *cond)
116129
{
117130
opal_atomic_lock(&cond->m_lock);
118131
if (NULL != cond->m_waiter_tail) {
119-
cond_waiter_t *p_cur_tail = (cond_waiter_t *) cond->m_waiter_tail;
132+
cond_waiter_t *p_cur_tail = (cond_waiter_t *)cond->m_waiter_tail;
120133
cond->m_waiter_tail = p_cur_tail->m_prev;
121134
/* Awaken one of threads. */
122135
p_cur_tail->m_signaled = 1;

opal/mca/threads/qthreads/threads_qthreads_mutex.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_recursive_mutex_t);
9898

9999
static inline void opal_mutex_create(struct opal_mutex_t *m)
100100
{
101+
opal_threads_ensure_init_qthreads();
102+
101103
opal_atomic_lock_init(&m->m_lock, 0);
102104
opal_atomic_lock_init(&m->m_lock_atomic, 0);
103105
m->m_recursive = 0;
@@ -108,9 +110,24 @@ static inline void opal_mutex_create(struct opal_mutex_t *m)
108110
#endif
109111
}
110112

113+
static inline void opal_mutex_recursive_create(struct opal_mutex_t *m)
114+
{
115+
opal_threads_ensure_init_qthreads();
116+
117+
opal_atomic_lock_init(&m->m_lock, 0);
118+
opal_atomic_lock_init(&m->m_lock_atomic, 0);
119+
m->m_recursive = 1;
120+
#if OPAL_ENABLE_DEBUG
121+
m->m_lock_debug = 0;
122+
m->m_lock_file = NULL;
123+
m->m_lock_line = 0;
124+
#endif
125+
}
126+
111127
static inline int opal_mutex_trylock(opal_mutex_t *m)
112128
{
113129
opal_threads_ensure_init_qthreads();
130+
114131
int ret = opal_atomic_trylock(&m->m_lock);
115132
if (0 != ret) {
116133
/* Yield to avoid a deadlock. */
@@ -122,6 +139,7 @@ static inline int opal_mutex_trylock(opal_mutex_t *m)
122139
static inline void opal_mutex_lock(opal_mutex_t *m)
123140
{
124141
opal_threads_ensure_init_qthreads();
142+
125143
int ret = opal_atomic_trylock(&m->m_lock);
126144
while (0 != ret) {
127145
qthread_yield();

0 commit comments

Comments
 (0)