Skip to content

Commit ade3b2f

Browse files
committed
Avoid using thread_local data if multi-threading is not enabled
Accessing thread-local data in a shared library is still expensive... Signed-off-by: Joseph Schuchart <schuchart@icl.utk.edu>
1 parent 8249d41 commit ade3b2f

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

ompi/mpiext/continue/c/continuation.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,12 +202,20 @@ struct thread_local_data_t {
202202
};
203203
typedef struct thread_local_data_t thread_local_data_t;
204204

205-
static opal_thread_local thread_local_data_t tl_data = { .in_progress = false, .is_initialized = false };
206-
207205
static __opal_attribute_always_inline__ inline
208206
thread_local_data_t* get_tl_data()
209207
{
210-
thread_local_data_t* tld = &tl_data;
208+
static opal_thread_local thread_local_data_t tl_data = { .in_progress = false, .is_initialized = false };
209+
/* process global tl_data if threads are disabled */
210+
static thread_local_data_t gl_data = { .in_progress = false, .is_initialized = false };
211+
212+
thread_local_data_t* tld;
213+
if (opal_using_threads()) {
214+
tld = &tl_data;
215+
} else {
216+
tld = &gl_data;
217+
}
218+
211219
if (OPAL_UNLIKELY(!tld->is_initialized)) {
212220
OBJ_CONSTRUCT(&tld->thread_progress_list, opal_list_t);
213221
OBJ_CONSTRUCT(&tld->tmplist, opal_list_t);
@@ -298,7 +306,7 @@ int ompi_continue_progress_n(const uint32_t max, thread_local_data_t *tld)
298306

299307
/* execute thread-local continuations first
300308
* (e.g., from continuation requests the current thread is waiting on) */
301-
if (tld->is_initialized) {
309+
if (!opal_list_is_empty(&tld->thread_progress_list)) {
302310
ompi_cont_request_t *cont_req;
303311
OPAL_LIST_FOREACH(cont_req, &tld->thread_progress_list, ompi_cont_request_t) {
304312
completed += ompi_continue_progress_request_n(cont_req, max - completed, tld);

0 commit comments

Comments
 (0)