Skip to content

Commit 8ef538a

Browse files
Merge pull request #2398 from bosilca/topic/tcp_endpoints_mutex
Protect the tcp_endpoints list from concurrent accesses.
2 parents 9a79da7 + d0dddef commit 8ef538a

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

opal/mca/btl/tcp/btl_tcp.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ mca_btl_tcp_module_t mca_btl_tcp_module = {
5050
.btl_put = mca_btl_tcp_put,
5151
.btl_dump = mca_btl_base_dump,
5252
.btl_ft_event = mca_btl_tcp_ft_event
53-
}
53+
},
54+
.tcp_endpoints_mutex = OPAL_MUTEX_STATIC_INIT
5455
};
5556

5657
/**
@@ -122,7 +123,9 @@ int mca_btl_tcp_add_procs( struct mca_btl_base_module_t* btl,
122123
continue;
123124
}
124125

126+
OPAL_THREAD_LOCK(&tcp_btl->tcp_endpoints_mutex);
125127
opal_list_append(&tcp_btl->tcp_endpoints, (opal_list_item_t*)tcp_endpoint);
128+
OPAL_THREAD_UNLOCK(&tcp_btl->tcp_endpoints_mutex);
126129
}
127130

128131
OPAL_THREAD_UNLOCK(&tcp_proc->proc_lock);
@@ -143,12 +146,14 @@ int mca_btl_tcp_add_procs( struct mca_btl_base_module_t* btl,
143146
}
144147

145148
int mca_btl_tcp_del_procs(struct mca_btl_base_module_t* btl,
146-
size_t nprocs,
147-
struct opal_proc_t **procs,
148-
struct mca_btl_base_endpoint_t ** endpoints)
149+
size_t nprocs,
150+
struct opal_proc_t **procs,
151+
struct mca_btl_base_endpoint_t ** endpoints)
149152
{
150153
mca_btl_tcp_module_t* tcp_btl = (mca_btl_tcp_module_t*)btl;
151154
size_t i;
155+
156+
OPAL_THREAD_LOCK(&tcp_btl->tcp_endpoints_mutex);
152157
for( i = 0; i < nprocs; i++ ) {
153158
mca_btl_tcp_endpoint_t* tcp_endpoint = endpoints[i];
154159
if(tcp_endpoint->endpoint_proc != mca_btl_tcp_proc_local()) {
@@ -157,6 +162,7 @@ int mca_btl_tcp_del_procs(struct mca_btl_base_module_t* btl,
157162
}
158163
opal_progress_event_users_decrement();
159164
}
165+
OPAL_THREAD_UNLOCK(&tcp_btl->tcp_endpoints_mutex);
160166
return OPAL_SUCCESS;
161167
}
162168

@@ -479,6 +485,10 @@ int mca_btl_tcp_finalize(struct mca_btl_base_module_t* btl)
479485
{
480486
mca_btl_tcp_module_t* tcp_btl = (mca_btl_tcp_module_t*) btl;
481487
opal_list_item_t* item;
488+
489+
/* Don't lock the tcp_endpoints_mutex, at this point a single
490+
* thread should be active.
491+
*/
482492
for( item = opal_list_remove_first(&tcp_btl->tcp_endpoints);
483493
item != NULL;
484494
item = opal_list_remove_first(&tcp_btl->tcp_endpoints)) {
@@ -512,11 +522,13 @@ void mca_btl_tcp_dump(struct mca_btl_base_module_t* base_btl,
512522
} else if( verbose ) {
513523
opal_list_item_t *item;
514524

525+
OPAL_THREAD_LOCK(&btl->tcp_endpoints_mutex);
515526
for(item = opal_list_get_first(&btl->tcp_endpoints);
516527
item != opal_list_get_end(&btl->tcp_endpoints);
517528
item = opal_list_get_next(item)) {
518529
MCA_BTL_TCP_ENDPOINT_DUMP(10, (mca_btl_base_endpoint_t*)item, false, "TCP");
519530
}
531+
OPAL_THREAD_UNLOCK(&btl->tcp_endpoints_mutex);
520532
}
521533
#endif /* OPAL_ENABLE_DEBUG && WANT_PEER_DUMP */
522534
}

opal/mca/btl/tcp/btl_tcp.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,10 @@ struct mca_btl_tcp_module_t {
170170
#endif
171171
struct sockaddr_storage tcp_ifaddr; /**< BTL interface address */
172172
uint32_t tcp_ifmask; /**< BTL interface netmask */
173+
174+
opal_mutex_t tcp_endpoints_mutex;
173175
opal_list_t tcp_endpoints;
176+
174177
mca_btl_base_module_error_cb_fn_t tcp_error_cb; /**< Upper layer error callback */
175178
#if MCA_BTL_TCP_STATISTICS
176179
size_t tcp_bytes_sent;

opal/mca/btl/tcp/btl_tcp_component.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,7 @@ static int mca_btl_tcp_create(int if_kindex, const char* if_name)
474474
return OPAL_ERR_OUT_OF_RESOURCE;
475475
memcpy(btl, &mca_btl_tcp_module, sizeof(mca_btl_tcp_module));
476476
OBJ_CONSTRUCT(&btl->tcp_endpoints, opal_list_t);
477+
OBJ_CONSTRUCT(&btl->tcp_endpoints_mutex, opal_mutex_t);
477478
mca_btl_tcp_component.tcp_btls[mca_btl_tcp_component.tcp_num_btls++] = btl;
478479

479480
/* initialize the btl */

0 commit comments

Comments
 (0)