17
17
* Copyright (c) 2019 Sandia National Laboratories. All rights reserved.
18
18
* Copyright (c) 2020 Triad National Security, LLC. All rights
19
19
* reserved.
20
- *
21
20
* Copyright (c) 2020 Cisco Systems, Inc. All rights reserved.
21
+ * Copyright (c) 2021 Argonne National Laboratory. All rights reserved.
22
22
* $COPYRIGHT$
23
23
*
24
24
* Additional copyrights may follow
34
34
#include <errno.h>
35
35
#include <stdio.h>
36
36
37
- #include "opal/mca/threads/argobots/threads_argobots.h"
38
-
39
37
#include "opal/class/opal_object.h"
38
+ #include "opal/mca/threads/argobots/threads_argobots.h"
39
+ #include "opal/mca/threads/mutex.h"
40
40
#include "opal/sys/atomic.h"
41
41
#include "opal/util/output.h"
42
42
43
43
BEGIN_C_DECLS
44
44
45
- /* Don't use ABT_MUTEX_NULL, since it might be not NULL. */
46
- #define OPAL_ABT_MUTEX_NULL 0
47
-
48
45
struct opal_mutex_t {
49
46
opal_object_t super ;
50
47
51
- ABT_mutex m_lock_argobots ;
48
+ ABT_mutex_memory m_lock_argobots ;
52
49
int m_recursive ;
53
50
54
51
#if OPAL_ENABLE_DEBUG
@@ -64,32 +61,34 @@ OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_mutex_t);
64
61
OPAL_DECLSPEC OBJ_CLASS_DECLARATION (opal_recursive_mutex_t );
65
62
66
63
#if OPAL_ENABLE_DEBUG
67
- # define OPAL_MUTEX_STATIC_INIT \
68
- { \
69
- .super = OPAL_OBJ_STATIC_INIT(opal_mutex_t), .m_lock_argobots = OPAL_ABT_MUTEX_NULL , \
70
- .m_recursive = 0, .m_lock_debug = 0, .m_lock_file = NULL, .m_lock_line = 0, \
71
- .m_lock_atomic = OPAL_ATOMIC_LOCK_INIT, \
64
+ # define OPAL_MUTEX_STATIC_INIT \
65
+ { \
66
+ .super = OPAL_OBJ_STATIC_INIT(opal_mutex_t), .m_lock_argobots = ABT_MUTEX_INITIALIZER , \
67
+ .m_recursive = 0, .m_lock_debug = 0, .m_lock_file = NULL, .m_lock_line = 0, \
68
+ .m_lock_atomic = OPAL_ATOMIC_LOCK_INIT, \
72
69
}
73
70
#else
74
- # define OPAL_MUTEX_STATIC_INIT \
75
- { \
76
- .super = OPAL_OBJ_STATIC_INIT(opal_mutex_t), .m_lock_argobots = OPAL_ABT_MUTEX_NULL , \
77
- .m_recursive = 0, .m_lock_atomic = OPAL_ATOMIC_LOCK_INIT, \
71
+ # define OPAL_MUTEX_STATIC_INIT \
72
+ { \
73
+ .super = OPAL_OBJ_STATIC_INIT(opal_mutex_t), .m_lock_argobots = ABT_MUTEX_INITIALIZER , \
74
+ .m_recursive = 0, .m_lock_atomic = OPAL_ATOMIC_LOCK_INIT, \
78
75
}
79
76
#endif
80
77
81
78
#if OPAL_ENABLE_DEBUG
82
- # define OPAL_RECURSIVE_MUTEX_STATIC_INIT \
83
- { \
84
- .super = OPAL_OBJ_STATIC_INIT(opal_mutex_t), .m_lock_argobots = OPAL_ABT_MUTEX_NULL, \
85
- .m_recursive = 1, .m_lock_debug = 0, .m_lock_file = NULL, .m_lock_line = 0, \
86
- .m_lock_atomic = OPAL_ATOMIC_LOCK_INIT, \
79
+ # define OPAL_RECURSIVE_MUTEX_STATIC_INIT \
80
+ { \
81
+ .super = OPAL_OBJ_STATIC_INIT(opal_mutex_t), \
82
+ .m_lock_argobots = ABT_RECURSIVE_MUTEX_INITIALIZER, .m_recursive = 1, \
83
+ .m_lock_debug = 0, .m_lock_file = NULL, .m_lock_line = 0, \
84
+ .m_lock_atomic = OPAL_ATOMIC_LOCK_INIT, \
87
85
}
88
86
#else
89
- # define OPAL_RECURSIVE_MUTEX_STATIC_INIT \
90
- { \
91
- .super = OPAL_OBJ_STATIC_INIT(opal_mutex_t), .m_lock_argobots = OPAL_ABT_MUTEX_NULL, \
92
- .m_recursive = 1, .m_lock_atomic = OPAL_ATOMIC_LOCK_INIT, \
87
+ # define OPAL_RECURSIVE_MUTEX_STATIC_INIT \
88
+ { \
89
+ .super = OPAL_OBJ_STATIC_INIT(opal_mutex_t), \
90
+ .m_lock_argobots = ABT_RECURSIVE_MUTEX_INITIALIZER, .m_recursive = 1, \
91
+ .m_lock_atomic = OPAL_ATOMIC_LOCK_INIT, \
93
92
}
94
93
#endif
95
94
@@ -99,14 +98,10 @@ OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_recursive_mutex_t);
99
98
*
100
99
************************************************************************/
101
100
102
- void opal_mutex_create (struct opal_mutex_t * m );
103
-
104
101
static inline int opal_mutex_trylock (opal_mutex_t * m )
105
102
{
106
- if (OPAL_ABT_MUTEX_NULL == m -> m_lock_argobots ) {
107
- opal_mutex_create (m );
108
- }
109
- int ret = ABT_mutex_trylock (m -> m_lock_argobots );
103
+ ABT_mutex mutex = ABT_MUTEX_MEMORY_GET_HANDLE (& m -> m_lock_argobots );
104
+ int ret = ABT_mutex_trylock (mutex );
110
105
if (ABT_ERR_MUTEX_LOCKED == ret ) {
111
106
return 1 ;
112
107
} else if (ABT_SUCCESS != ret ) {
@@ -120,31 +115,27 @@ static inline int opal_mutex_trylock(opal_mutex_t *m)
120
115
121
116
static inline void opal_mutex_lock (opal_mutex_t * m )
122
117
{
123
- if (OPAL_ABT_MUTEX_NULL == m -> m_lock_argobots ) {
124
- opal_mutex_create (m );
125
- }
118
+ ABT_mutex mutex = ABT_MUTEX_MEMORY_GET_HANDLE (& m -> m_lock_argobots );
126
119
#if OPAL_ENABLE_DEBUG
127
- int ret = ABT_mutex_lock (m -> m_lock_argobots );
120
+ int ret = ABT_mutex_lock (mutex );
128
121
if (ABT_SUCCESS != ret ) {
129
122
opal_output (0 , "opal_mutex_lock()" );
130
123
}
131
124
#else
132
- ABT_mutex_lock (m -> m_lock_argobots );
125
+ ABT_mutex_lock (mutex );
133
126
#endif
134
127
}
135
128
136
129
static inline void opal_mutex_unlock (opal_mutex_t * m )
137
130
{
138
- if (OPAL_ABT_MUTEX_NULL == m -> m_lock_argobots ) {
139
- opal_mutex_create (m );
140
- }
131
+ ABT_mutex mutex = ABT_MUTEX_MEMORY_GET_HANDLE (& m -> m_lock_argobots );
141
132
#if OPAL_ENABLE_DEBUG
142
- int ret = ABT_mutex_unlock (m -> m_lock_argobots );
133
+ int ret = ABT_mutex_unlock (mutex );
143
134
if (ABT_SUCCESS != ret ) {
144
135
opal_output (0 , "opal_mutex_unlock()" );
145
136
}
146
137
#else
147
- ABT_mutex_unlock (m -> m_lock_argobots );
138
+ ABT_mutex_unlock (mutex );
148
139
#endif
149
140
/* For fairness of locking. */
150
141
ABT_thread_yield ();
@@ -200,9 +191,8 @@ static inline void opal_mutex_atomic_unlock(opal_mutex_t *m)
200
191
201
192
#endif
202
193
203
- #define OPAL_ABT_COND_NULL NULL
204
- typedef ABT_cond opal_cond_t ;
205
- #define OPAL_CONDITION_STATIC_INIT OPAL_ABT_COND_NULL
194
+ typedef ABT_cond_memory opal_cond_t ;
195
+ #define OPAL_CONDITION_STATIC_INIT ABT_COND_INITIALIZER
206
196
207
197
int opal_cond_init (opal_cond_t * cond );
208
198
int opal_cond_wait (opal_cond_t * cond , opal_mutex_t * lock );
0 commit comments