@@ -62,19 +62,25 @@ int mca_base_source_init (void)
62
62
{
63
63
int ret = OPAL_SUCCESS ;
64
64
65
+ OPAL_THREAD_LOCK (& mca_base_source_lock );
66
+
65
67
if (false == mca_base_source_initialized ) {
66
68
mca_base_source_initialized = true;
67
69
68
70
OBJ_CONSTRUCT (& registered_sources , opal_pointer_array_t );
69
71
opal_pointer_array_init (& registered_sources , 16 , 512 , 16 );
70
72
73
+ OPAL_THREAD_UNLOCK (& mca_base_source_lock );
74
+
71
75
/* mca_base_source_register will use lock */
72
76
mca_base_source_default_source = mca_base_source_register ("opal" , "mca" , "base" , "default_source" ,
73
77
"Default source for MCA events" , true,
74
78
mca_base_source_default_time_source ,
75
79
mca_base_source_default_time_source_ticks ());
76
80
77
81
}
82
+ else
83
+ OPAL_THREAD_UNLOCK (& mca_base_source_lock );
78
84
79
85
return ret ;
80
86
}
@@ -83,6 +89,7 @@ int mca_base_source_finalize (void)
83
89
{
84
90
int i ;
85
91
92
+ OPAL_THREAD_LOCK (& mca_base_source_lock );
86
93
if (true == mca_base_source_initialized ) {
87
94
for (i = 0 ; i < source_count ; ++ i ) {
88
95
mca_base_source_t * source = opal_pointer_array_get_item (& registered_sources , i );
@@ -96,6 +103,7 @@ int mca_base_source_finalize (void)
96
103
OBJ_DESTRUCT (& registered_sources );
97
104
mca_base_source_initialized = false;
98
105
}
106
+ OPAL_THREAD_UNLOCK (& mca_base_source_lock );
99
107
100
108
return OPAL_SUCCESS ;
101
109
}
@@ -152,10 +160,12 @@ int mca_base_source_get_count (int *count)
152
160
return OPAL_SUCCESS ;
153
161
}
154
162
163
+ /* This function should be under mca_base_source_lock. */
164
+ /* Due to this being called only from mca_base_source_register() currently, */
165
+ /* and that is under such lock, there aren't any locks here. */
166
+ /* This should be considered if this needs to be called from somewhere else. */
155
167
static inline int mca_base_source_get_by_name (const char * name , mca_base_source_t * * source_out )
156
168
{
157
- OPAL_THREAD_LOCK (& mca_base_source_lock );
158
-
159
169
/* there are expected to be a relatively small number of sources so a linear search should be fine */
160
170
for (int i = 0 ; i < source_count ; ++ i ) {
161
171
mca_base_source_t * source = opal_pointer_array_get_item (& registered_sources , i );
@@ -169,7 +179,6 @@ static inline int mca_base_source_get_by_name (const char *name, mca_base_source
169
179
}
170
180
}
171
181
172
- OPAL_THREAD_UNLOCK (& mca_base_source_lock );
173
182
return OPAL_ERR_NOT_FOUND ;
174
183
}
175
184
@@ -180,9 +189,12 @@ int mca_base_source_register (const char *project, const char *framework, const
180
189
char * source_name ;
181
190
int ret ;
182
191
192
+ OPAL_THREAD_LOCK (& mca_base_source_lock );
193
+
183
194
/* generate the variable's full name */
184
195
ret = mca_base_var_generate_full_name4 (NULL , framework , component , name , & source_name );
185
196
if (OPAL_SUCCESS != ret ) {
197
+ OPAL_THREAD_UNLOCK (& mca_base_source_lock );
186
198
return ret ;
187
199
}
188
200
@@ -193,6 +205,7 @@ int mca_base_source_register (const char *project, const char *framework, const
193
205
/* create a new parameter entry */
194
206
source = OBJ_NEW (mca_base_source_t );
195
207
if (NULL == source ) {
208
+ OPAL_THREAD_UNLOCK (& mca_base_source_lock );
196
209
return OPAL_ERR_OUT_OF_RESOURCE ;
197
210
}
198
211
@@ -219,6 +232,7 @@ int mca_base_source_register (const char *project, const char *framework, const
219
232
220
233
if (OPAL_SUCCESS != ret ) {
221
234
OBJ_RELEASE (source );
235
+ OPAL_THREAD_UNLOCK (& mca_base_source_lock );
222
236
return ret ;
223
237
}
224
238
} else {
@@ -234,6 +248,8 @@ int mca_base_source_register (const char *project, const char *framework, const
234
248
source -> source_time = source_time ;
235
249
source -> source_ticks = source_ticks ;
236
250
251
+ OPAL_THREAD_UNLOCK (& mca_base_source_lock );
252
+
237
253
return OPAL_SUCCESS ;
238
254
}
239
255
int mca_base_component_source_register (const mca_base_component_t * component , const char * name , const char * description , bool ordered ,
0 commit comments