@@ -62,19 +62,25 @@ int mca_base_source_init (void)
6262{
6363 int ret = OPAL_SUCCESS ;
6464
65+ OPAL_THREAD_LOCK (& mca_base_source_lock );
66+
6567 if (false == mca_base_source_initialized ) {
6668 mca_base_source_initialized = true;
6769
6870 OBJ_CONSTRUCT (& registered_sources , opal_pointer_array_t );
6971 opal_pointer_array_init (& registered_sources , 16 , 512 , 16 );
7072
73+ OPAL_THREAD_UNLOCK (& mca_base_source_lock );
74+
7175 /* mca_base_source_register will use lock */
7276 mca_base_source_default_source = mca_base_source_register ("opal" , "mca" , "base" , "default_source" ,
7377 "Default source for MCA events" , true,
7478 mca_base_source_default_time_source ,
7579 mca_base_source_default_time_source_ticks ());
7680
7781 }
82+ else
83+ OPAL_THREAD_UNLOCK (& mca_base_source_lock );
7884
7985 return ret ;
8086}
@@ -83,6 +89,7 @@ int mca_base_source_finalize (void)
8389{
8490 int i ;
8591
92+ OPAL_THREAD_LOCK (& mca_base_source_lock );
8693 if (true == mca_base_source_initialized ) {
8794 for (i = 0 ; i < source_count ; ++ i ) {
8895 mca_base_source_t * source = opal_pointer_array_get_item (& registered_sources , i );
@@ -96,6 +103,7 @@ int mca_base_source_finalize (void)
96103 OBJ_DESTRUCT (& registered_sources );
97104 mca_base_source_initialized = false;
98105 }
106+ OPAL_THREAD_UNLOCK (& mca_base_source_lock );
99107
100108 return OPAL_SUCCESS ;
101109}
@@ -152,10 +160,12 @@ int mca_base_source_get_count (int *count)
152160 return OPAL_SUCCESS ;
153161}
154162
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. */
155167static inline int mca_base_source_get_by_name (const char * name , mca_base_source_t * * source_out )
156168{
157- OPAL_THREAD_LOCK (& mca_base_source_lock );
158-
159169 /* there are expected to be a relatively small number of sources so a linear search should be fine */
160170 for (int i = 0 ; i < source_count ; ++ i ) {
161171 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
169179 }
170180 }
171181
172- OPAL_THREAD_UNLOCK (& mca_base_source_lock );
173182 return OPAL_ERR_NOT_FOUND ;
174183}
175184
@@ -180,9 +189,12 @@ int mca_base_source_register (const char *project, const char *framework, const
180189 char * source_name ;
181190 int ret ;
182191
192+ OPAL_THREAD_LOCK (& mca_base_source_lock );
193+
183194 /* generate the variable's full name */
184195 ret = mca_base_var_generate_full_name4 (NULL , framework , component , name , & source_name );
185196 if (OPAL_SUCCESS != ret ) {
197+ OPAL_THREAD_UNLOCK (& mca_base_source_lock );
186198 return ret ;
187199 }
188200
@@ -193,6 +205,7 @@ int mca_base_source_register (const char *project, const char *framework, const
193205 /* create a new parameter entry */
194206 source = OBJ_NEW (mca_base_source_t );
195207 if (NULL == source ) {
208+ OPAL_THREAD_UNLOCK (& mca_base_source_lock );
196209 return OPAL_ERR_OUT_OF_RESOURCE ;
197210 }
198211
@@ -219,6 +232,7 @@ int mca_base_source_register (const char *project, const char *framework, const
219232
220233 if (OPAL_SUCCESS != ret ) {
221234 OBJ_RELEASE (source );
235+ OPAL_THREAD_UNLOCK (& mca_base_source_lock );
222236 return ret ;
223237 }
224238 } else {
@@ -234,6 +248,8 @@ int mca_base_source_register (const char *project, const char *framework, const
234248 source -> source_time = source_time ;
235249 source -> source_ticks = source_ticks ;
236250
251+ OPAL_THREAD_UNLOCK (& mca_base_source_lock );
252+
237253 return OPAL_SUCCESS ;
238254}
239255int mca_base_component_source_register (const mca_base_component_t * component , const char * name , const char * description , bool ordered ,
0 commit comments