Skip to content

Commit d498325

Browse files
authored
Merge pull request #4 from shintaro-iwasaki/threads-squash-rebase-pth
Clean up mca/pthreads
2 parents 6514506 + e574970 commit d498325

File tree

5 files changed

+66
-24
lines changed

5 files changed

+66
-24
lines changed

opal/mca/pmix/base/base.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,11 @@ OPAL_DECLSPEC int opal_pmix_base_exchange(opal_value_t *info,
5555

5656
OPAL_DECLSPEC void opal_pmix_base_set_evbase(opal_event_base_t *evbase);
5757

58-
#define opal_pmix_condition_wait(a,b) pthread_cond_wait(a, &(b)->m_lock_pthread)
59-
typedef pthread_cond_t opal_pmix_condition_t;
60-
#define opal_pmix_condition_broadcast(a) pthread_cond_broadcast(a)
61-
#define opal_pmix_condition_signal(a) pthread_cond_signal(a)
62-
#define OPAL_PMIX_CONDITION_STATIC_INIT PTHREAD_COND_INITIALIZER
58+
#define opal_pmix_condition_wait(a,b) opal_cond_wait(a, b)
59+
typedef opal_cond_t opal_pmix_condition_t;
60+
#define opal_pmix_condition_broadcast(a) opal_cond_broadcast(a)
61+
#define opal_pmix_condition_signal(a) opal_cond_signal(a)
62+
#define OPAL_PMIX_CONDITION_STATIC_INIT OPAL_CONDITION_STATIC_INIT
6363

6464
typedef struct {
6565
opal_mutex_t mutex;
@@ -81,7 +81,7 @@ extern opal_pmix_base_t opal_pmix_base;
8181
#define OPAL_PMIX_CONSTRUCT_LOCK(l) \
8282
do { \
8383
OBJ_CONSTRUCT(&(l)->mutex, opal_mutex_t); \
84-
pthread_cond_init(&(l)->cond, NULL); \
84+
opal_cond_init(&(l)->cond); \
8585
(l)->active = true; \
8686
OPAL_POST_OBJECT((l)); \
8787
} while(0)
@@ -90,7 +90,7 @@ extern opal_pmix_base_t opal_pmix_base;
9090
do { \
9191
OPAL_ACQUIRE_OBJECT((l)); \
9292
OBJ_DESTRUCT(&(l)->mutex); \
93-
pthread_cond_destroy(&(l)->cond); \
93+
opal_cond_destroy(&(l)->cond); \
9494
} while(0)
9595

9696

opal/mca/threads/pthreads/threads_pthreads_mutex.c

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,6 @@
3131
#include "opal/mca/threads/mutex.h"
3232
//#include "opal/mca/threads/pthreads/mutex_unix.h"
3333

34-
35-
OBJ_CLASS_INSTANCE(opal_mutex_t,
36-
opal_object_t,
37-
NULL,
38-
NULL);
39-
OBJ_CLASS_INSTANCE(opal_recursive_mutex_t,
40-
opal_object_t,
41-
NULL,
42-
NULL);
43-
4434
/*
4535
* Wait and see if some upper layer wants to use threads, if support
4636
* exists.
@@ -63,3 +53,46 @@ struct opal_pthread_mutex_t {
6353
typedef struct opal_pthread_mutex_t opal_pthread_mutex_t;
6454
typedef struct opal_pthread_mutex_t opal_pthread_recursive_mutex_t;
6555

56+
static void mca_threads_pthreads_mutex_constructor(opal_mutex_t *p_mutex) {
57+
pthread_mutex_init(&p_mutex->m_lock_pthread, NULL);
58+
#if OPAL_ENABLE_DEBUG
59+
p_mutex->m_lock_debug = 0;
60+
p_mutex->m_lock_file = NULL;
61+
p_mutex->m_lock_line = 0;
62+
#endif
63+
opal_atomic_lock_init(&p_mutex->m_lock_atomic, 0);
64+
}
65+
66+
static void mca_threads_pthreads_mutex_desctructor(opal_mutex_t *p_mutex) {
67+
pthread_mutex_destroy(&p_mutex->m_lock_pthread);
68+
}
69+
70+
static void mca_threads_pthreads_recursive_mutex_constructor
71+
(opal_recursive_mutex_t *p_mutex) {
72+
pthread_mutexattr_t mutex_attr;
73+
pthread_mutexattr_init(&mutex_attr);
74+
pthread_mutexattr_settype(&mutex_attr, PTHREAD_MUTEX_RECURSIVE);
75+
pthread_mutex_init(&p_mutex->m_lock_pthread, &mutex_attr);
76+
pthread_mutexattr_destroy(&mutex_attr);
77+
#if OPAL_ENABLE_DEBUG
78+
p_mutex->m_lock_debug = 0;
79+
p_mutex->m_lock_file = NULL;
80+
p_mutex->m_lock_line = 0;
81+
#endif
82+
opal_atomic_lock_init(&p_mutex->m_lock_atomic, 0);
83+
}
84+
85+
static void mca_threads_pthreads_recursive_mutex_desctructor
86+
(opal_recursive_mutex_t *p_mutex) {
87+
pthread_mutex_destroy(&p_mutex->m_lock_pthread);
88+
}
89+
90+
OBJ_CLASS_INSTANCE(opal_mutex_t,
91+
opal_object_t,
92+
mca_threads_pthreads_mutex_constructor,
93+
mca_threads_pthreads_mutex_desctructor);
94+
95+
OBJ_CLASS_INSTANCE(opal_recursive_mutex_t,
96+
opal_object_t,
97+
mca_threads_pthreads_recursive_mutex_constructor,
98+
mca_threads_pthreads_recursive_mutex_desctructor);

opal/mca/threads/pthreads/threads_pthreads_mutex.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,14 @@ static inline void opal_mutex_atomic_unlock(opal_mutex_t *m)
211211

212212
#endif
213213

214+
typedef pthread_cond_t opal_cond_t;
215+
#define OPAL_CONDITION_STATIC_INIT PTHREAD_COND_INITIALIZER
216+
#define opal_cond_init(a) pthread_cond_init(a, NULL)
217+
#define opal_cond_wait(a,b) pthread_cond_wait(a, &(b)->m_lock_pthread)
218+
#define opal_cond_broadcast(a) pthread_cond_broadcast(a)
219+
#define opal_cond_signal(a) pthread_cond_signal(a)
220+
#define opal_cond_destroy(a) pthread_cond_destroy(a)
221+
214222
END_C_DECLS
215223

216224
#endif /* OPAL_MCA_THREADS_PTHREADS_THREADS_PTHREADS_MUTEX_H */

opal/mca/timer/linux/timer_linux_component.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "opal_config.h"
2727

2828
#include <string.h>
29+
#include <time.h>
2930

3031
#include "opal/mca/timer/timer.h"
3132
#include "opal/mca/timer/base/base.h"

orte/util/threads.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@
2727
* we only have a memory barrier */
2828
#define ORTE_ACQUIRE_OBJECT(o) opal_atomic_rmb()
2929

30-
#define orte_condition_wait(a,b) pthread_cond_wait(a, &(b)->m_lock_pthread)
31-
typedef pthread_cond_t orte_condition_t;
32-
#define orte_condition_broadcast(a) pthread_cond_broadcast(a)
33-
#define orte_condition_signal(a) pthread_cond_signal(a)
34-
#define ORTE_CONDITION_STATIC_INIT PTHREAD_COND_INITIALIZER
30+
#define orte_condition_wait(a,b) opal_cond_wait(a,b)
31+
typedef opal_cond_t orte_condition_t;
32+
#define orte_condition_broadcast(a) opal_cond_broadcast(a)
33+
#define orte_condition_signal(a) opal_cond_signal(a)
34+
#define ORTE_CONDITION_STATIC_INIT OPAL_COND_INITIALIZER
3535

3636
/* define a threadshift macro */
3737
#define ORTE_THREADSHIFT(x, eb, f, p) \
@@ -51,14 +51,14 @@ typedef struct {
5151
#define ORTE_CONSTRUCT_LOCK(l) \
5252
do { \
5353
OBJ_CONSTRUCT(&(l)->mutex, opal_mutex_t); \
54-
pthread_cond_init(&(l)->cond, NULL); \
54+
opal_cond_init(&(l)->cond); \
5555
(l)->active = true; \
5656
} while(0)
5757

5858
#define ORTE_DESTRUCT_LOCK(l) \
5959
do { \
6060
OBJ_DESTRUCT(&(l)->mutex); \
61-
pthread_cond_destroy(&(l)->cond); \
61+
opal_cond_destroy(&(l)->cond); \
6262
} while(0)
6363

6464

0 commit comments

Comments
 (0)