From cbf5ba0dd43b8b9b137d7c1fb863c2e531893b35 Mon Sep 17 00:00:00 2001 From: Shintaro Iwasaki Date: Thu, 31 Oct 2019 14:46:37 -0500 Subject: [PATCH] /opal/mca/threads: clean up Signed-off-by: Shintaro Iwasaki --- opal/mca/threads/argobots/threads_argobots.h | 12 +- .../argobots/threads_argobots_component.c | 4 +- .../argobots/threads_argobots_condition.c | 3 +- .../threads/argobots/threads_argobots_event.c | 45 +++--- .../argobots/threads_argobots_module.c | 57 +++++--- .../threads/argobots/threads_argobots_mutex.c | 26 ++-- .../threads/argobots/threads_argobots_mutex.h | 77 +++++----- .../argobots/threads_argobots_threads.h | 8 +- .../threads/argobots/threads_argobots_tsd.h | 19 ++- .../argobots/threads_argobots_wait_sync.c | 38 ++--- .../argobots/threads_argobots_wait_sync.h | 28 ++-- opal/mca/threads/base/base.h | 9 +- opal/mca/threads/base/threads_base_open.c | 8 +- opal/mca/threads/condition.h | 40 +++--- opal/mca/threads/mutex.h | 48 +++---- .../pthreads/threads_pthreads_component.c | 2 +- .../pthreads/threads_pthreads_condition.c | 1 + .../pthreads/threads_pthreads_module.c | 40 +++--- .../threads/pthreads/threads_pthreads_mutex.c | 12 +- .../threads/pthreads/threads_pthreads_mutex.h | 20 +-- .../pthreads/threads_pthreads_threads.h | 6 +- .../threads/pthreads/threads_pthreads_tsd.h | 13 +- .../pthreads/threads_pthreads_wait_sync.c | 44 +++--- .../pthreads/threads_pthreads_wait_sync.h | 22 +-- .../qthreads/threads_qthreads_component.c | 9 +- .../qthreads/threads_qthreads_module.c | 25 +--- .../threads/qthreads/threads_qthreads_mutex.c | 47 +----- opal/mca/threads/thread.h | 9 +- opal/mca/threads/thread_usage.h | 135 ++++++++++-------- opal/mca/threads/threads.h | 24 ++-- opal/mca/threads/tsd.h | 3 +- opal/mca/threads/wait_sync.h | 20 +-- 32 files changed, 425 insertions(+), 429 deletions(-) diff --git a/opal/mca/threads/argobots/threads_argobots.h b/opal/mca/threads/argobots/threads_argobots.h index 5dfa18647cb..75f80cb301d 100644 --- a/opal/mca/threads/argobots/threads_argobots.h +++ b/opal/mca/threads/argobots/threads_argobots.h @@ -23,14 +23,16 @@ * $HEADER$ */ -#ifndef OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_H -#define OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_H 1 +#ifndef OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_H +#define OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_H #include -static inline void ensure_init_argobots(void) { - if (ABT_initialized() != 0) - ABT_init(0, 0); +static inline void opal_threads_argobots_ensure_init(void) +{ + if (ABT_initialized() != 0) { + ABT_init(0, 0); + } } #endif /* OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_H */ diff --git a/opal/mca/threads/argobots/threads_argobots_component.c b/opal/mca/threads/argobots/threads_argobots_component.c index b72b0bca859..6d3fd0a519c 100644 --- a/opal/mca/threads/argobots/threads_argobots_component.c +++ b/opal/mca/threads/argobots/threads_argobots_component.c @@ -33,7 +33,7 @@ static int opal_threads_argobots_open(void); const opal_threads_base_component_1_0_0_t mca_threads_argobots_component = { /* First, the mca_component_t struct containing meta information - about the component itself */ + * about the component itself */ .threadsc_version = { OPAL_THREADS_BASE_VERSION_1_0_0, @@ -52,6 +52,6 @@ const opal_threads_base_component_1_0_0_t mca_threads_argobots_component = { int opal_threads_argobots_open(void) { - ensure_init_argobots(); + opal_threads_argobots_ensure_init(); return OPAL_SUCCESS; } diff --git a/opal/mca/threads/argobots/threads_argobots_condition.c b/opal/mca/threads/argobots/threads_argobots_condition.c index 6e7c2868569..56b11cf9526 100644 --- a/opal/mca/threads/argobots/threads_argobots_condition.c +++ b/opal/mca/threads/argobots/threads_argobots_condition.c @@ -1,3 +1,4 @@ +/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */ /* * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana * University Research and Technology @@ -22,14 +23,12 @@ #include "opal/mca/threads/condition.h" - static void opal_condition_construct(opal_condition_t *c) { c->c_waiting = 0; c->c_signaled = 0; } - static void opal_condition_destruct(opal_condition_t *c) { } diff --git a/opal/mca/threads/argobots/threads_argobots_event.c b/opal/mca/threads/argobots/threads_argobots_event.c index 7f3dc5df99f..c9ad79476b8 100644 --- a/opal/mca/threads/argobots/threads_argobots_event.c +++ b/opal/mca/threads/argobots/threads_argobots_event.c @@ -17,8 +17,7 @@ #include -static void * -evthread_argobots_lock_alloc(unsigned locktype) +static void *evthread_argobots_lock_alloc(unsigned locktype) { ABT_mutex lock; if (locktype & EVTHREAD_LOCKTYPE_RECURSIVE) { @@ -33,15 +32,13 @@ evthread_argobots_lock_alloc(unsigned locktype) return lock; } -static void -evthread_argobots_lock_free(void *_lock, unsigned locktype) +static void evthread_argobots_lock_free(void *_lock, unsigned locktype) { ABT_mutex lock = _lock; ABT_mutex_free(&lock); } -static int -evthread_argobots_lock(unsigned mode, void *_lock) +static int evthread_argobots_lock(unsigned mode, void *_lock) { int ret; ABT_mutex lock = _lock; @@ -53,8 +50,7 @@ evthread_argobots_lock(unsigned mode, void *_lock) return ret; } -static int -evthread_argobots_unlock(unsigned mode, void *_lock) +static int evthread_argobots_unlock(unsigned mode, void *_lock) { ABT_mutex lock = _lock; int ret = ABT_mutex_unlock(lock); @@ -63,43 +59,40 @@ evthread_argobots_unlock(unsigned mode, void *_lock) return ret; } -static unsigned long -evthread_argobots_get_id(void) +static unsigned long evthread_argobots_get_id(void) { ABT_thread thr; ABT_thread_self(&thr); return (unsigned long)((intptr_t)thr); } -static void * -evthread_argobots_cond_alloc(unsigned condflags) +static void *evthread_argobots_cond_alloc(unsigned condflags) { ABT_cond cond; ABT_cond_create(&cond); return cond; } -static void -evthread_argobots_cond_free(void *_cond) +static void evthread_argobots_cond_free(void *_cond) { ABT_cond cond = _cond; ABT_cond_free(&cond); } -static int -evthread_argobots_cond_signal(void *_cond, int broadcast) +static int evthread_argobots_cond_signal(void *_cond, int broadcast) { ABT_cond cond = _cond; int r; - if (broadcast) + if (broadcast) { r = ABT_cond_broadcast(cond); - else + } else { r = ABT_cond_signal(cond); + } return r ? -1 : 0; } -static int -evthread_argobots_cond_wait(void *_cond, void *_lock, const struct timeval *tv) +static int evthread_argobots_cond_wait(void *_cond, void *_lock, + const struct timeval *tv) { int r; ABT_cond cond = _cond; @@ -111,19 +104,21 @@ evthread_argobots_cond_wait(void *_cond, void *_lock, const struct timeval *tv) evutil_gettimeofday(&now, NULL); evutil_timeradd(&now, tv, &abstime); ts.tv_sec = abstime.tv_sec; - ts.tv_nsec = abstime.tv_usec*1000; + ts.tv_nsec = abstime.tv_usec * 1000; r = ABT_cond_timedwait(cond, lock, &ts); - if (r != 0) + if (r != 0) { return 1; - else + } else { return 0; + } } else { r = ABT_cond_wait(cond, lock); return r ? -1 : 0; } } -void opal_event_use_threads(void) { +void opal_event_use_threads(void) +{ struct evthread_lock_callbacks cbs = { EVTHREAD_LOCK_API_VERSION, EVTHREAD_LOCKTYPE_RECURSIVE, @@ -139,7 +134,7 @@ void opal_event_use_threads(void) { evthread_argobots_cond_signal, evthread_argobots_cond_wait }; - ensure_init_argobots(); + opal_threads_argobots_ensure_init(); evthread_set_lock_callbacks(&cbs); evthread_set_condition_callbacks(&cond_cbs); evthread_set_id_callback(evthread_argobots_get_id); diff --git a/opal/mca/threads/argobots/threads_argobots_module.c b/opal/mca/threads/argobots/threads_argobots_module.c index 5dc95348808..464e3a25b7d 100644 --- a/opal/mca/threads/argobots/threads_argobots_module.c +++ b/opal/mca/threads/argobots/threads_argobots_module.c @@ -1,3 +1,4 @@ +/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */ /* * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana * University Research and Technology @@ -17,6 +18,7 @@ * * $HEADER$ */ + #include #include "opal/mca/threads/argobots/threads_argobots.h" @@ -51,20 +53,22 @@ OBJ_CLASS_INSTANCE(opal_thread_t, opal_object_t, opal_thread_construct, NULL); -static inline ABT_thread opal_thread_get_argobots_self(void) { +static inline ABT_thread opal_thread_get_argobots_self(void) +{ ABT_thread self; ABT_thread_self(&self); return self; } -static void opal_thread_argobots_wrapper(void *arg) { - opal_thread_t *t = (opal_thread_t *) arg; - t->t_ret = ((void*(*)(void*)) t->t_run)(t); +static void opal_thread_argobots_wrapper(void *arg) +{ + opal_thread_t *t = (opal_thread_t *)arg; + t->t_ret = ((void *(*)(void *))t->t_run)(t); } opal_thread_t *opal_thread_get_self(void) { - ensure_init_argobots(); + opal_threads_argobots_ensure_init(); opal_thread_t *t = OBJ_NEW(opal_thread_t); t->t_handle = opal_thread_get_argobots_self(); return t; @@ -72,26 +76,30 @@ opal_thread_t *opal_thread_get_self(void) bool opal_thread_self_compare(opal_thread_t *t) { - ensure_init_argobots(); - return t->t_handle == opal_thread_get_argobots_self(); + opal_threads_argobots_ensure_init(); + return opal_thread_get_argobots_self() == t->t_handle; } -int opal_thread_join(opal_thread_t *t, void **thr_return) { - ensure_init_argobots(); +int opal_thread_join(opal_thread_t *t, void **thr_return) +{ + opal_threads_argobots_ensure_init(); int rc = ABT_thread_free(&t->t_handle); - if (thr_return) + if (thr_return) { *thr_return = t->t_ret; + } t->t_handle = ABT_THREAD_NULL; - return (rc == 0) ? OPAL_SUCCESS : OPAL_ERROR; + return (0 == rc) ? OPAL_SUCCESS : OPAL_ERROR; } -void opal_thread_set_main() { - ensure_init_argobots(); +void opal_thread_set_main() +{ + opal_threads_argobots_ensure_init(); opal_main_thread = opal_thread_get_argobots_self(); } -int opal_thread_start(opal_thread_t *t) { - ensure_init_argobots(); +int opal_thread_start(opal_thread_t *t) +{ + opal_threads_argobots_ensure_init(); int rc; if (OPAL_ENABLE_DEBUG) { if (NULL == t->t_run || t->t_handle != ABT_THREAD_NULL) { @@ -105,32 +113,35 @@ int opal_thread_start(opal_thread_t *t) { opal_thread_argobots_wrapper, t, ABT_THREAD_ATTR_NULL, &t->t_handle); - return (rc == 0) ? OPAL_SUCCESS : OPAL_ERROR; + return (0 == rc) ? OPAL_SUCCESS : OPAL_ERROR; } opal_class_t opal_thread_t_class; int opal_tsd_key_create(opal_tsd_key_t *key, opal_tsd_destructor_t destructor) { - ensure_init_argobots(); + opal_threads_argobots_ensure_init(); int rc; rc = ABT_key_create(destructor, key); if ((0 == rc) && (opal_thread_get_argobots_self() == opal_main_thread)) { - opal_tsd_key_values = (struct opal_tsd_key_value *)realloc(opal_tsd_key_values, (opal_tsd_key_values_count+1) * sizeof(struct opal_tsd_key_value)); + opal_tsd_key_values = (struct opal_tsd_key_value *) + realloc(opal_tsd_key_values, (opal_tsd_key_values_count + 1) * + sizeof(struct opal_tsd_key_value)); opal_tsd_key_values[opal_tsd_key_values_count].key = *key; opal_tsd_key_values[opal_tsd_key_values_count].destructor = destructor; - opal_tsd_key_values_count ++; + opal_tsd_key_values_count++; } return rc; } int opal_tsd_keys_destruct(void) { - ensure_init_argobots(); + opal_threads_argobots_ensure_init(); int i; - void * ptr; - for (i=0; im_lock_argobots = OPAL_ABT_MUTEX_NULL; p_mutex->m_recursive = 0; #if OPAL_ENABLE_DEBUG @@ -49,15 +50,18 @@ static void mca_threads_argobots_mutex_constructor(opal_mutex_t *p_mutex) { opal_atomic_lock_init(&p_mutex->m_lock_atomic, 0); } -static void mca_threads_argobots_mutex_desctructor(opal_mutex_t *p_mutex) { - ensure_init_argobots(); - if (OPAL_ABT_MUTX_NULL != p_mutex->m_lock_argobots) +static void mca_threads_argobots_mutex_desctructor(opal_mutex_t *p_mutex) +{ + opal_threads_argobots_ensure_init(); + if (OPAL_ABT_MUTEX_NULL != p_mutex->m_lock_argobots) { ABT_mutex_free(&p_mutex->m_lock_argobots); + } } static void mca_threads_argobots_recursive_mutex_constructor - (opal_recursive_mutex_t *p_mutex) { - ensure_init_argobots(); + (opal_recursive_mutex_t *p_mutex) +{ + opal_threads_argobots_ensure_init(); p_mutex->m_lock_argobots = OPAL_ABT_MUTEX_NULL; p_mutex->m_recursive = 1; #if OPAL_ENABLE_DEBUG @@ -69,10 +73,12 @@ static void mca_threads_argobots_recursive_mutex_constructor } static void mca_threads_argobots_recursive_mutex_desctructor - (opal_recursive_mutex_t *p_mutex) { - ensure_init_argobots(); - if (OPAL_ABT_MUTEX_NULL != p_mutex->m_lock_argobots) + (opal_recursive_mutex_t *p_mutex) +{ + opal_threads_argobots_ensure_init(); + if (OPAL_ABT_MUTEX_NULL != p_mutex->m_lock_argobots) { ABT_mutex_free(&p_mutex->m_lock_argobots); + } } OBJ_CLASS_INSTANCE(opal_mutex_t, diff --git a/opal/mca/threads/argobots/threads_argobots_mutex.h b/opal/mca/threads/argobots/threads_argobots_mutex.h index e0c41f5398d..e9d26a06750 100644 --- a/opal/mca/threads/argobots/threads_argobots_mutex.h +++ b/opal/mca/threads/argobots/threads_argobots_mutex.h @@ -15,7 +15,7 @@ * Copyright (c) 2015-2016 Research Organization for Information Science * and Technology (RIST). All rights reserved. * Copyright (c) 2019 Sandia National Laboratories. All rights reserved. - * + * * $COPYRIGHT$ * * Additional copyrights may follow @@ -23,19 +23,8 @@ * $HEADER$ */ -#ifndef OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_MUTEX_H -#define OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_MUTEX_H 1 - -/** - * @file: - * - * Mutual exclusion functions: Unix implementation. - * - * Functions for locking of critical sections. - * - * On unix, use Argobots or our own atomic operations as - * available. - */ +#ifndef OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_MUTEX_H +#define OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_MUTEX_H #include "opal/mca/threads/argobots/threads_argobots.h" #include "opal_config.h" @@ -109,7 +98,8 @@ OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_recursive_mutex_t); * ************************************************************************/ -static inline void opal_mutex_create(struct opal_mutex_t *m) { +static inline void opal_mutex_create(struct opal_mutex_t *m) +{ while (OPAL_ABT_MUTEX_NULL == m->m_lock_argobots) { ABT_mutex abt_mutex; if (m->m_recursive) { @@ -134,9 +124,10 @@ static inline void opal_mutex_create(struct opal_mutex_t *m) { static inline int opal_mutex_trylock(opal_mutex_t *m) { - ensure_init_argobots(); - if (OPAL_ABT_MUTEX_NULL == m->m_lock_argobots) + opal_threads_argobots_ensure_init(); + if (OPAL_ABT_MUTEX_NULL == m->m_lock_argobots) { opal_mutex_create(m); + } #if OPAL_ENABLE_DEBUG int ret = ABT_mutex_trylock(m->m_lock_argobots); if (ret != 0) { @@ -152,9 +143,10 @@ static inline int opal_mutex_trylock(opal_mutex_t *m) static inline void opal_mutex_lock(opal_mutex_t *m) { - ensure_init_argobots(); - if (OPAL_ABT_MUTEX_NULL == m->m_lock_argobots) + opal_threads_argobots_ensure_init(); + if (OPAL_ABT_MUTEX_NULL == m->m_lock_argobots) { opal_mutex_create(m); + } #if OPAL_ENABLE_DEBUG int ret = ABT_mutex_lock(m->m_lock_argobots); if (ret != 0) { @@ -169,9 +161,10 @@ static inline void opal_mutex_lock(opal_mutex_t *m) static inline void opal_mutex_unlock(opal_mutex_t *m) { - ensure_init_argobots(); - if (OPAL_ABT_MUTEX_NULL == m->m_lock_argobots) + opal_threads_argobots_ensure_init(); + if (OPAL_ABT_MUTEX_NULL == m->m_lock_argobots) { opal_mutex_create(m); + } #if OPAL_ENABLE_DEBUG int ret = ABT_mutex_unlock(m->m_lock_argobots); if (ret != 0) { @@ -240,8 +233,9 @@ static inline void opal_mutex_atomic_unlock(opal_mutex_t *m) typedef ABT_cond opal_cond_t; #define OPAL_CONDITION_STATIC_INIT OPAL_ABT_COND_NULL -static inline void opal_cond_create(opal_cond_t *cond) { - ensure_init_argobots(); +static inline void opal_cond_create(opal_cond_t *cond) +{ + opal_threads_argobots_ensure_init(); while (OPAL_ABT_COND_NULL == *cond) { ABT_cond new_cond; ABT_cond_create(&new_cond); @@ -256,39 +250,48 @@ static inline void opal_cond_create(opal_cond_t *cond) { } } -static inline int opal_cond_init(opal_cond_t *cond) { +static inline int opal_cond_init(opal_cond_t *cond) +{ *cond = OPAL_ABT_COND_NULL; return 0; } -static inline int opal_cond_wait(opal_cond_t *cond, opal_mutex_t *lock) { - ensure_init_argobots(); - if (OPAL_ABT_COND_NULL == *cond) +static inline int opal_cond_wait(opal_cond_t *cond, opal_mutex_t *lock) +{ + opal_threads_argobots_ensure_init(); + if (OPAL_ABT_COND_NULL == *cond) { opal_cond_create(cond); + } return ABT_cond_wait(*cond, lock->m_lock_argobots); } -static inline int opal_cond_broadcast(opal_cond_t *cond) { - ensure_init_argobots(); - if (OPAL_ABT_COND_NULL == *cond) +static inline int opal_cond_broadcast(opal_cond_t *cond) +{ + opal_threads_argobots_ensure_init(); + if (OPAL_ABT_COND_NULL == *cond) { opal_cond_create(cond); + } return ABT_cond_broadcast(*cond); } -static inline int opal_cond_signal(opal_cond_t *cond) { - ensure_init_argobots(); - if (OPAL_ABT_COND_NULL == *cond) +static inline int opal_cond_signal(opal_cond_t *cond) +{ + opal_threads_argobots_ensure_init(); + if (OPAL_ABT_COND_NULL == *cond) { opal_cond_create(cond); + } return ABT_cond_signal(*cond); } -static inline int opal_cond_destroy(opal_cond_t *cond) { - ensure_init_argobots(); - if (OPAL_ABT_COND_NULL != *cond) +static inline int opal_cond_destroy(opal_cond_t *cond) +{ + opal_threads_argobots_ensure_init(); + if (OPAL_ABT_COND_NULL != * cond) { ABT_cond_free(cond); + } return 0; } END_C_DECLS -#endif /* OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_MUTEX_H */ +#endif /* OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_MUTEX_H */ diff --git a/opal/mca/threads/argobots/threads_argobots_threads.h b/opal/mca/threads/argobots/threads_argobots_threads.h index 78e09767fb2..5d85369fa98 100644 --- a/opal/mca/threads/argobots/threads_argobots_threads.h +++ b/opal/mca/threads/argobots/threads_argobots_threads.h @@ -23,8 +23,8 @@ * $HEADER$ */ -#ifndef OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_THREADS_H -#define OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_THREADS_H 1 +#ifndef OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_THREADS_H +#define OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_THREADS_H #include #include @@ -32,9 +32,9 @@ struct opal_thread_t { opal_object_t super; opal_thread_fn_t t_run; - void* t_arg; + void *t_arg; ABT_thread t_handle; - void* t_ret; + void *t_ret; }; #endif /* OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_THREADS_H */ diff --git a/opal/mca/threads/argobots/threads_argobots_tsd.h b/opal/mca/threads/argobots/threads_argobots_tsd.h index 7582724db8a..6385d9b2c47 100644 --- a/opal/mca/threads/argobots/threads_argobots_tsd.h +++ b/opal/mca/threads/argobots/threads_argobots_tsd.h @@ -24,32 +24,29 @@ */ -#ifndef OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_TSD_H -#define OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_TSD_H 1 +#ifndef OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_TSD_H +#define OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_TSD_H #include "opal/mca/threads/argobots/threads_argobots.h" #include typedef ABT_key opal_tsd_key_t; -static inline int -opal_tsd_key_delete(opal_tsd_key_t key) +static inline int opal_tsd_key_delete(opal_tsd_key_t key) { - ensure_init_argobots(); + opal_threads_argobots_ensure_init(); return ABT_key_free(&key); } -static inline int -opal_tsd_setspecific(opal_tsd_key_t key, void *value) +static inline int opal_tsd_setspecific(opal_tsd_key_t key, void *value) { - ensure_init_argobots(); + opal_threads_argobots_ensure_init(); return ABT_key_set(key, value); } -static inline int -opal_tsd_getspecific(opal_tsd_key_t key, void **valuep) +static inline int opal_tsd_getspecific(opal_tsd_key_t key, void **valuep) { - ensure_init_argobots(); + opal_threads_argobots_ensure_init(); ABT_key_get(key, valuep); return OPAL_SUCCESS; } diff --git a/opal/mca/threads/argobots/threads_argobots_wait_sync.c b/opal/mca/threads/argobots/threads_argobots_wait_sync.c index dddb7eafbf7..e11e1fc3a74 100644 --- a/opal/mca/threads/argobots/threads_argobots_wait_sync.c +++ b/opal/mca/threads/argobots/threads_argobots_wait_sync.c @@ -14,31 +14,33 @@ * * $HEADER$ */ + #include "opal/mca/threads/argobots/threads_argobots.h" #include "opal/mca/threads/wait_sync.h" static opal_mutex_t wait_sync_lock = OPAL_MUTEX_STATIC_INIT; -static ompi_wait_sync_t* wait_sync_list = NULL; +static ompi_wait_sync_t *wait_sync_list = NULL; static opal_atomic_int32_t num_thread_in_progress = 0; #define WAIT_SYNC_PASS_OWNERSHIP(who) \ do { \ - ensure_init_argobots(); \ + opal_threads_argobots_ensure_init(); \ ABT_mutex_lock((who)->lock); \ ABT_cond_signal((who)->condition ); \ ABT_mutex_unlock((who)->lock); \ - } while(0) + } while (0) int ompi_sync_wait_mt(ompi_wait_sync_t *sync) { - ensure_init_argobots(); + opal_threads_argobots_ensure_init(); /* Don't stop if the waiting synchronization is completed. We avoid the * race condition around the release of the synchronization using the * signaling field. */ - if(sync->count <= 0) + if (sync->count <= 0) { return (0 == sync->status) ? OPAL_SUCCESS : OPAL_ERROR; + } /* lock so nobody can signal us during the list updating */ ABT_mutex_lock(sync->lock); @@ -46,14 +48,14 @@ int ompi_sync_wait_mt(ompi_wait_sync_t *sync) /* Now that we hold the lock make sure another thread has not already * call cond_signal. */ - if(sync->count <= 0) { + if (sync->count <= 0) { ABT_mutex_unlock(sync->lock); return (0 == sync->status) ? OPAL_SUCCESS : OPAL_ERROR; } /* Insert sync on the list of pending synchronization constructs */ OPAL_THREAD_LOCK(&wait_sync_lock); - if( NULL == wait_sync_list ) { + if (NULL == wait_sync_list) { sync->next = sync->prev = sync; wait_sync_list = sync; } else { @@ -65,12 +67,14 @@ int ompi_sync_wait_mt(ompi_wait_sync_t *sync) OPAL_THREAD_UNLOCK(&wait_sync_lock); /** - * If we are not responsible for progresing, go silent until something worth noticing happen: + * If we are not responsible for progressing, go silent until something + * worth noticing happen: * - this thread has been promoted to take care of the progress * - our sync has been triggered. */ - check_status: - if( sync != wait_sync_list && num_thread_in_progress >= opal_max_thread_in_progress) { + check_status: + if (sync != wait_sync_list && + num_thread_in_progress >= opal_max_thread_in_progress) { ABT_cond_wait(sync->condition, sync->lock); /** @@ -79,7 +83,7 @@ int ompi_sync_wait_mt(ompi_wait_sync_t *sync) * promoted as the progress manager. */ - if( sync->count <= 0 ) { /* Completed? */ + if (sync->count <= 0) { /* Completed? */ ABT_mutex_unlock(sync->lock); goto i_am_done; } @@ -89,22 +93,24 @@ int ompi_sync_wait_mt(ompi_wait_sync_t *sync) ABT_mutex_unlock(sync->lock); OPAL_THREAD_ADD_FETCH32(&num_thread_in_progress, 1); - while(sync->count > 0) { /* progress till completion */ - opal_progress(); /* don't progress with the sync lock locked or you'll deadlock */ + while (sync->count > 0) { /* progress till completion */ + /* don't progress with the sync lock locked or you'll deadlock */ + opal_progress(); ABT_thread_yield(); } OPAL_THREAD_ADD_FETCH32(&num_thread_in_progress, -1); - i_am_done: + i_am_done: /* My sync is now complete. Trim the list: remove self, wake next */ OPAL_THREAD_LOCK(&wait_sync_lock); sync->prev->next = sync->next; sync->next->prev = sync->prev; /* In case I am the progress manager, pass the duties on */ - if( sync == wait_sync_list ) { + if (sync == wait_sync_list) { wait_sync_list = (sync == sync->next) ? NULL : sync->next; - if( NULL != wait_sync_list ) + if (NULL != wait_sync_list) { WAIT_SYNC_PASS_OWNERSHIP(wait_sync_list); + } } OPAL_THREAD_UNLOCK(&wait_sync_lock); diff --git a/opal/mca/threads/argobots/threads_argobots_wait_sync.h b/opal/mca/threads/argobots/threads_argobots_wait_sync.h index b9d5041294f..dfb66e76cb5 100644 --- a/opal/mca/threads/argobots/threads_argobots_wait_sync.h +++ b/opal/mca/threads/argobots/threads_argobots_wait_sync.h @@ -23,9 +23,8 @@ * $HEADER$ */ - -#ifndef OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_WAIT_SYNC_H -#define OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_WAIT_SYNC_H 1 +#ifndef OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_WAIT_SYNC_H +#define OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_WAIT_SYNC_H #include "opal/mca/threads/argobots/threads_argobots.h" #include @@ -40,7 +39,8 @@ typedef struct ompi_wait_sync_t { volatile bool signaling; } ompi_wait_sync_t; -#define SYNC_WAIT(sync) (opal_using_threads() ? ompi_sync_wait_mt (sync) : sync_wait_st (sync)) +#define SYNC_WAIT(sync) \ + (opal_using_threads() ? ompi_sync_wait_mt (sync) : sync_wait_st (sync)) /* The loop in release handles a race condition between the signaling * thread and the destruction of the condition variable. The signaling @@ -52,7 +52,7 @@ typedef struct ompi_wait_sync_t { * the critical path. */ #define WAIT_SYNC_RELEASE(sync) \ if (opal_using_threads()) { \ - ensure_init_argobots(); \ + opal_threads_argobots_ensure_init(); \ while ((sync)->signaling) { \ ABT_thread_yield(); \ continue; \ @@ -63,7 +63,7 @@ typedef struct ompi_wait_sync_t { #define WAIT_SYNC_RELEASE_NOWAIT(sync) \ if (opal_using_threads()) { \ - ensure_init_argobots(); \ + opal_threads_argobots_ensure_init(); \ ABT_cond_free(&(sync)->condition); \ ABT_mutex_free(&(sync)->lock); \ } @@ -71,26 +71,26 @@ typedef struct ompi_wait_sync_t { #define WAIT_SYNC_SIGNAL(sync) \ if (opal_using_threads()) { \ - ensure_init_argobots(); \ + opal_threads_argobots_ensure_init(); \ ABT_mutex_lock(sync->lock); \ ABT_cond_signal(sync->condition); \ ABT_mutex_unlock(sync->lock); \ sync->signaling = false; \ } -#define WAIT_SYNC_SIGNALLED(sync){ \ +#define WAIT_SYNC_SIGNALLED(sync) \ + { \ (sync)->signaling = false; \ -} + } OPAL_DECLSPEC int ompi_sync_wait_mt(ompi_wait_sync_t *sync); -static inline int sync_wait_st (ompi_wait_sync_t *sync) +static inline int sync_wait_st(ompi_wait_sync_t *sync) { - ensure_init_argobots(); + opal_threads_argobots_ensure_init(); while (sync->count > 0) { opal_progress(); ABT_thread_yield(); } - return sync->status; } @@ -103,10 +103,10 @@ static inline int sync_wait_st (ompi_wait_sync_t *sync) (sync)->status = 0; \ (sync)->signaling = (0 != (c)); \ if (opal_using_threads()) { \ - ensure_init_argobots(); \ + opal_threads_argobots_ensure_init(); \ ABT_cond_create (&(sync)->condition); \ ABT_mutex_create (&(sync)->lock); \ } \ - } while(0) + } while (0) #endif /* OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_WAIT_SYNC_H */ diff --git a/opal/mca/threads/base/base.h b/opal/mca/threads/base/base.h index f407a1784c2..dd774005068 100644 --- a/opal/mca/threads/base/base.h +++ b/opal/mca/threads/base/base.h @@ -1,3 +1,4 @@ +/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */ /* * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana * University Research and Technology @@ -9,7 +10,7 @@ * University of Stuttgart. All rights reserved. * Copyright (c) 2004-2005 The Regents of the University of California. * All rights reserved. - * Copyright (c) 2014 Cisco Systems, Inc. All rights reserved. + * Copyright (c) 2014 Cisco Systems, Inc. All rights reserved. * Copyright (c) 2019 Sandia National Laboratories. All rights reserved. * * $COPYRIGHT$ @@ -20,8 +21,8 @@ * */ -#ifndef OPAL_THREADS_BASE_H -#define OPAL_THREADS_BASE_H +#ifndef OPAL_MCA_THREADS_BASE_BASE_H +#define OPAL_MCA_THREADS_BASE_BASE_H #include "opal_config.h" #include "opal/mca/base/mca_base_framework.h" @@ -44,4 +45,4 @@ END_C_DECLS /* include implementation to call */ #include MCA_threads_base_include_HEADER -#endif /* OPAL_BASE_THREADS_H */ +#endif /* OPAL_MCA_THREADS_BASE_BASE_H */ diff --git a/opal/mca/threads/base/threads_base_open.c b/opal/mca/threads/base/threads_base_open.c index 4b497280a34..25fb95b28ce 100644 --- a/opal/mca/threads/base/threads_base_open.c +++ b/opal/mca/threads/base/threads_base_open.c @@ -1,3 +1,4 @@ +/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */ /* * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana * University Research and Technology @@ -9,7 +10,7 @@ * University of Stuttgart. All rights reserved. * Copyright (c) 2004-2005 The Regents of the University of California. * All rights reserved. - * Copyright (c) 2014 Cisco Systems, Inc. All rights reserved. + * Copyright (c) 2014 Cisco Systems, Inc. All rights reserved. * Copyright (c) 2019 Sandia National Laboratories. All rights reserved. * * $COPYRIGHT$ @@ -19,13 +20,11 @@ * $HEADER$ */ - #include "opal_config.h" #include "opal/constants.h" #include "opal/mca/threads/base/base.h" - /* * The following file was created by configure. It contains extern * statements and the definition of an array of pointers to each @@ -42,5 +41,6 @@ static int mca_threads_base_register(mca_base_register_flag_t flags) * Globals */ /* Use default register/open/close functions */ -MCA_BASE_FRAMEWORK_DECLARE(opal, threads, "OPAL OS threads", mca_threads_base_register, NULL, NULL, +MCA_BASE_FRAMEWORK_DECLARE(opal, threads, "OPAL OS threads", + mca_threads_base_register, NULL, NULL, mca_threads_base_static_components, 0); diff --git a/opal/mca/threads/condition.h b/opal/mca/threads/condition.h index d5533a20d84..65b15978642 100644 --- a/opal/mca/threads/condition.h +++ b/opal/mca/threads/condition.h @@ -1,3 +1,4 @@ +/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */ /* * Copyright (c) 2004-2007 The Trustees of Indiana University and Indiana * University Research and Technology @@ -17,13 +18,13 @@ * Copyright (c) 2019 Triad National Security, LLC. All rights * reserved. * - * * $COPYRIGHT$ * * Additional copyrights may follow * * $HEADER$ */ + #ifndef OPAL_MCA_THREADS_CONDITION_H #define OPAL_MCA_THREADS_CONDITION_H @@ -70,14 +71,14 @@ static inline int opal_condition_wait(opal_condition_t *c, opal_mutex_t *m) opal_mutex_lock(m); return 0; } - while (c->c_signaled == 0) { + while (0 == c->c_signaled) { opal_mutex_unlock(m); opal_progress(); OPAL_CR_TEST_CHECKPOINT_READY_STALL(); opal_mutex_lock(m); } } else { - while (c->c_signaled == 0) { + while (0 == c->c_signaled) { opal_progress(); OPAL_CR_TEST_CHECKPOINT_READY_STALL(); } @@ -88,8 +89,7 @@ static inline int opal_condition_wait(opal_condition_t *c, opal_mutex_t *m) return rc; } -static inline int opal_condition_timedwait(opal_condition_t *c, - opal_mutex_t *m, +static inline int opal_condition_timedwait(opal_condition_t *c, opal_mutex_t *m, const struct timespec *abstime) { struct timeval tv; @@ -100,32 +100,34 @@ static inline int opal_condition_timedwait(opal_condition_t *c, if (opal_using_threads()) { absolute.tv_sec = abstime->tv_sec; absolute.tv_usec = abstime->tv_nsec / 1000; - gettimeofday(&tv,NULL); - if (c->c_signaled == 0) { + gettimeofday(&tv, NULL); + if (0 == c->c_signaled) { do { opal_mutex_unlock(m); opal_progress(); - gettimeofday(&tv,NULL); + gettimeofday(&tv, NULL); opal_mutex_lock(m); - } while (c->c_signaled == 0 && - (tv.tv_sec <= absolute.tv_sec || - (tv.tv_sec == absolute.tv_sec && tv.tv_usec < absolute.tv_usec))); + } while (0 == c->c_signaled && (tv.tv_sec <= absolute.tv_sec || + (tv.tv_sec == absolute.tv_sec && + tv.tv_usec < absolute.tv_usec))); } } else { absolute.tv_sec = abstime->tv_sec; absolute.tv_usec = abstime->tv_nsec / 1000; - gettimeofday(&tv,NULL); - if (c->c_signaled == 0) { + gettimeofday(&tv, NULL); + if (0 == c->c_signaled) { do { opal_progress(); - gettimeofday(&tv,NULL); - } while (c->c_signaled == 0 && - (tv.tv_sec <= absolute.tv_sec || - (tv.tv_sec == absolute.tv_sec && tv.tv_usec < absolute.tv_usec))); + gettimeofday(&tv, NULL); + } while (0 == c->c_signaled && (tv.tv_sec <= absolute.tv_sec || + (tv.tv_sec == absolute.tv_sec && + tv.tv_usec < absolute.tv_usec))); } } - if (c->c_signaled != 0) c->c_signaled--; + if (0 != c->c_signaled) { + c->c_signaled--; + } c->c_waiting--; return rc; } @@ -146,4 +148,4 @@ static inline int opal_condition_broadcast(opal_condition_t *c) END_C_DECLS -#endif // OPAL_MCA_THREADS_CONDITION_H +#endif /* OPAL_MCA_THREADS_CONDITION_H */ diff --git a/opal/mca/threads/mutex.h b/opal/mca/threads/mutex.h index 35a5812d20a..a81e94cb6e8 100644 --- a/opal/mca/threads/mutex.h +++ b/opal/mca/threads/mutex.h @@ -24,15 +24,15 @@ * $HEADER$ */ -#ifndef OPAL_MCA_THREADS_MUTEX_H -#define OPAL_MCA_THREADS_MUTEX_H 1 +#ifndef OPAL_MCA_THREADS_MUTEX_H +#define OPAL_MCA_THREADS_MUTEX_H #include "opal_config.h" BEGIN_C_DECLS /** -* @file: + * @file: * * Mutual exclusion functions. * @@ -115,11 +115,11 @@ static inline void opal_mutex_atomic_unlock(opal_mutex_t *mutex); * If there is no possibility that multiple threads are running in the * process, return immediately. */ -#define OPAL_THREAD_LOCK(mutex) \ - do { \ - if (OPAL_UNLIKELY(opal_using_threads())) { \ - opal_mutex_lock(mutex); \ - } \ +#define OPAL_THREAD_LOCK(mutex) \ + do { \ + if (OPAL_UNLIKELY(opal_using_threads())) { \ + opal_mutex_lock(mutex); \ + } \ } while (0) @@ -138,7 +138,7 @@ static inline void opal_mutex_atomic_unlock(opal_mutex_t *mutex); * * Returns 0 if mutex was locked, non-zero otherwise. */ -#define OPAL_THREAD_TRYLOCK(mutex) \ +#define OPAL_THREAD_TRYLOCK(mutex) \ (OPAL_UNLIKELY(opal_using_threads()) ? opal_mutex_trylock(mutex) : 0) /** @@ -154,11 +154,11 @@ static inline void opal_mutex_atomic_unlock(opal_mutex_t *mutex); * If there is no possibility that multiple threads are running in the * process, return immediately without modifying the mutex. */ -#define OPAL_THREAD_UNLOCK(mutex) \ - do { \ - if (OPAL_UNLIKELY(opal_using_threads())) { \ - opal_mutex_unlock(mutex); \ - } \ +#define OPAL_THREAD_UNLOCK(mutex) \ + do { \ + if (OPAL_UNLIKELY(opal_using_threads())) { \ + opal_mutex_unlock(mutex); \ + } \ } while (0) @@ -177,17 +177,17 @@ static inline void opal_mutex_atomic_unlock(opal_mutex_t *mutex); * If there is no possibility that multiple threads are running in the * process, invoke the action without acquiring the lock. */ -#define OPAL_THREAD_SCOPED_LOCK(mutex, action) \ - do { \ - if(OPAL_UNLIKELY(opal_using_threads())) { \ - opal_mutex_lock(mutex); \ - action; \ - opal_mutex_unlock(mutex); \ - } else { \ - action; \ - } \ +#define OPAL_THREAD_SCOPED_LOCK(mutex, action) \ + do { \ + if (OPAL_UNLIKELY(opal_using_threads())) { \ + opal_mutex_lock(mutex); \ + action; \ + opal_mutex_unlock(mutex); \ + } else { \ + action; \ + } \ } while (0) END_C_DECLS -#endif /* OPAL_MCA_THREADS_MUTEX_H */ +#endif /* OPAL_MCA_THREADS_MUTEX_H */ diff --git a/opal/mca/threads/pthreads/threads_pthreads_component.c b/opal/mca/threads/pthreads/threads_pthreads_component.c index 85339d1381c..fcd00368831 100644 --- a/opal/mca/threads/pthreads/threads_pthreads_component.c +++ b/opal/mca/threads/pthreads/threads_pthreads_component.c @@ -31,7 +31,7 @@ static int opal_threads_pthreads_open(void); const opal_threads_base_component_1_0_0_t mca_threads_pthreads_component = { /* First, the mca_component_t struct containing meta information - about the component itself */ + * about the component itself */ .threadsc_version = { OPAL_THREADS_BASE_VERSION_1_0_0, diff --git a/opal/mca/threads/pthreads/threads_pthreads_condition.c b/opal/mca/threads/pthreads/threads_pthreads_condition.c index 6e7c2868569..9af788d9241 100644 --- a/opal/mca/threads/pthreads/threads_pthreads_condition.c +++ b/opal/mca/threads/pthreads/threads_pthreads_condition.c @@ -1,3 +1,4 @@ +/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */ /* * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana * University Research and Technology diff --git a/opal/mca/threads/pthreads/threads_pthreads_module.c b/opal/mca/threads/pthreads/threads_pthreads_module.c index a6a7483122e..819eb27ab80 100644 --- a/opal/mca/threads/pthreads/threads_pthreads_module.c +++ b/opal/mca/threads/pthreads/threads_pthreads_module.c @@ -47,13 +47,12 @@ static int opal_tsd_key_values_count = 0; static void opal_thread_construct(opal_thread_t *t) { t->t_run = 0; - t->t_handle = (pthread_t) -1; + t->t_handle = (pthread_t)-1; } OBJ_CLASS_INSTANCE(opal_thread_t, opal_object_t, opal_thread_construct, NULL); - opal_thread_t *opal_thread_get_self(void) @@ -65,31 +64,34 @@ opal_thread_t *opal_thread_get_self(void) bool opal_thread_self_compare(opal_thread_t *t) { - return t->t_handle == pthread_self(); + return pthread_self() == t->t_handle; } -int opal_thread_join(opal_thread_t *t, void **thr_return) { +int opal_thread_join(opal_thread_t *t, void **thr_return) +{ int rc = pthread_join(t->t_handle, thr_return); - t->t_handle = (pthread_t) -1; - return (rc == 0) ? OPAL_SUCCESS : OPAL_ERROR; + t->t_handle = (pthread_t)-1; + return (0 == rc) ? OPAL_SUCCESS : OPAL_ERROR; } -void opal_thread_set_main() { +void opal_thread_set_main(void) +{ opal_main_thread = pthread_self(); } -int opal_thread_start(opal_thread_t *t) { +int opal_thread_start(opal_thread_t *t) +{ int rc; if (OPAL_ENABLE_DEBUG) { - if (NULL == t->t_run || t->t_handle != (pthread_t) -1) { + if (NULL == t->t_run || t->t_handle != (pthread_t)-1) { return OPAL_ERR_BAD_PARAM; } } - rc = pthread_create(&t->t_handle, NULL, (void*(*)(void*)) t->t_run, t); + rc = pthread_create(&t->t_handle, NULL, (void *(*)(void *))t->t_run, t); - return (rc == 0) ? OPAL_SUCCESS : OPAL_ERROR; + return (0 == rc) ? OPAL_SUCCESS : OPAL_ERROR; } opal_class_t opal_thread_t_class; @@ -99,10 +101,12 @@ int opal_tsd_key_create(opal_tsd_key_t *key, opal_tsd_destructor_t destructor) int rc; rc = pthread_key_create(key, destructor); if ((0 == rc) && (pthread_self() == opal_main_thread)) { - opal_tsd_key_values = (struct opal_tsd_key_value *)realloc(opal_tsd_key_values, (opal_tsd_key_values_count+1) * sizeof(struct opal_tsd_key_value)); + opal_tsd_key_values = (struct opal_tsd_key_value *) + realloc(opal_tsd_key_values, (opal_tsd_key_values_count + 1) * + sizeof(struct opal_tsd_key_value)); opal_tsd_key_values[opal_tsd_key_values_count].key = *key; opal_tsd_key_values[opal_tsd_key_values_count].destructor = destructor; - opal_tsd_key_values_count ++; + opal_tsd_key_values_count++; } return rc; } @@ -110,9 +114,10 @@ int opal_tsd_key_create(opal_tsd_key_t *key, opal_tsd_destructor_t destructor) int opal_tsd_keys_destruct(void) { int i; - void * ptr; - for (i=0; im_lock_pthread, NULL); #if OPAL_ENABLE_DEBUG p_mutex->m_lock_debug = 0; @@ -62,12 +63,14 @@ static void mca_threads_pthreads_mutex_constructor(opal_mutex_t *p_mutex) { opal_atomic_lock_init(&p_mutex->m_lock_atomic, 0); } -static void mca_threads_pthreads_mutex_desctructor(opal_mutex_t *p_mutex) { +static void mca_threads_pthreads_mutex_desctructor(opal_mutex_t *p_mutex) +{ pthread_mutex_destroy(&p_mutex->m_lock_pthread); } static void mca_threads_pthreads_recursive_mutex_constructor - (opal_recursive_mutex_t *p_mutex) { + (opal_recursive_mutex_t *p_mutex) +{ pthread_mutexattr_t mutex_attr; pthread_mutexattr_init(&mutex_attr); pthread_mutexattr_settype(&mutex_attr, PTHREAD_MUTEX_RECURSIVE); @@ -82,7 +85,8 @@ static void mca_threads_pthreads_recursive_mutex_constructor } static void mca_threads_pthreads_recursive_mutex_desctructor - (opal_recursive_mutex_t *p_mutex) { + (opal_recursive_mutex_t *p_mutex) +{ pthread_mutex_destroy(&p_mutex->m_lock_pthread); } diff --git a/opal/mca/threads/pthreads/threads_pthreads_mutex.h b/opal/mca/threads/pthreads/threads_pthreads_mutex.h index 3f8d082c4b4..e42e6ddc900 100644 --- a/opal/mca/threads/pthreads/threads_pthreads_mutex.h +++ b/opal/mca/threads/pthreads/threads_pthreads_mutex.h @@ -15,7 +15,7 @@ * Copyright (c) 2015-2016 Research Organization for Information Science * and Technology (RIST). All rights reserved. * Copyright (c) 2019 Sandia National Laboratories. All rights reserved. - * + * * $COPYRIGHT$ * * Additional copyrights may follow @@ -23,8 +23,8 @@ * $HEADER$ */ -#ifndef OPAL_MCA_THREADS_PTHREADS_THREADS_PTHREADS_MUTEX_H -#define OPAL_MCA_THREADS_PTHREADS_THREADS_PTHREADS_MUTEX_H 1 +#ifndef OPAL_MCA_THREADS_PTHREADS_THREADS_PTHREADS_MUTEX_H +#define OPAL_MCA_THREADS_PTHREADS_THREADS_PTHREADS_MUTEX_H /** * @file: @@ -65,9 +65,11 @@ OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_mutex_t); OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_recursive_mutex_t); #if defined(PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP) -#define OPAL_PTHREAD_RECURSIVE_MUTEX_INITIALIZER PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP +#define OPAL_PTHREAD_RECURSIVE_MUTEX_INITIALIZER \ + PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP #elif defined(PTHREAD_RECURSIVE_MUTEX_INITIALIZER) -#define OPAL_PTHREAD_RECURSIVE_MUTEX_INITIALIZER PTHREAD_RECURSIVE_MUTEX_INITIALIZER +#define OPAL_PTHREAD_RECURSIVE_MUTEX_INITIALIZER \ + PTHREAD_RECURSIVE_MUTEX_INITIALIZER #endif #if OPAL_ENABLE_DEBUG @@ -122,7 +124,7 @@ static inline int opal_mutex_trylock(opal_mutex_t *m) { #if OPAL_ENABLE_DEBUG int ret = pthread_mutex_trylock(&m->m_lock_pthread); - if (ret == EDEADLK) { + if (EDEADLK == ret) { errno = ret; perror("opal_mutex_trylock()"); abort(); @@ -137,7 +139,7 @@ static inline void opal_mutex_lock(opal_mutex_t *m) { #if OPAL_ENABLE_DEBUG int ret = pthread_mutex_lock(&m->m_lock_pthread); - if (ret == EDEADLK) { + if (EDEADLK == ret) { errno = ret; perror("opal_mutex_lock()"); abort(); @@ -151,7 +153,7 @@ static inline void opal_mutex_unlock(opal_mutex_t *m) { #if OPAL_ENABLE_DEBUG int ret = pthread_mutex_unlock(&m->m_lock_pthread); - if (ret == EPERM) { + if (EPERM == ret) { errno = ret; perror("opal_mutex_unlock"); abort(); @@ -221,4 +223,4 @@ typedef pthread_cond_t opal_cond_t; END_C_DECLS -#endif /* OPAL_MCA_THREADS_PTHREADS_THREADS_PTHREADS_MUTEX_H */ +#endif /* OPAL_MCA_THREADS_PTHREADS_THREADS_PTHREADS_MUTEX_H */ diff --git a/opal/mca/threads/pthreads/threads_pthreads_threads.h b/opal/mca/threads/pthreads/threads_pthreads_threads.h index 45e5e8f87ed..27ad13e8e1d 100644 --- a/opal/mca/threads/pthreads/threads_pthreads_threads.h +++ b/opal/mca/threads/pthreads/threads_pthreads_threads.h @@ -24,8 +24,8 @@ */ -#ifndef OPAL_MCA_THREADS_PTHREADS_THREADS_PTHREADS_THREADS_H -#define OPAL_MCA_THREADS_PTHREADS_THREADS_PTHREADS_THREADS_H 1 +#ifndef OPAL_MCA_THREADS_PTHREADS_THREADS_PTHREADS_THREADS_H +#define OPAL_MCA_THREADS_PTHREADS_THREADS_PTHREADS_THREADS_H #include #include @@ -33,7 +33,7 @@ struct opal_thread_t { opal_object_t super; opal_thread_fn_t t_run; - void* t_arg; + void *t_arg; pthread_t t_handle; }; diff --git a/opal/mca/threads/pthreads/threads_pthreads_tsd.h b/opal/mca/threads/pthreads/threads_pthreads_tsd.h index 001d20aa042..2d1955eea7f 100644 --- a/opal/mca/threads/pthreads/threads_pthreads_tsd.h +++ b/opal/mca/threads/pthreads/threads_pthreads_tsd.h @@ -24,28 +24,25 @@ */ -#ifndef OPAL_MCA_THREADS_PTHREADS_THREADS_PTHREADS_TSD_H -#define OPAL_MCA_THREADS_PTHREADS_THREADS_PTHREADS_TSD_H 1 +#ifndef OPAL_MCA_THREADS_PTHREADS_THREADS_PTHREADS_TSD_H +#define OPAL_MCA_THREADS_PTHREADS_THREADS_PTHREADS_TSD_H #include #include typedef pthread_key_t opal_tsd_key_t; -static inline int -opal_tsd_key_delete(opal_tsd_key_t key) +static inline int opal_tsd_key_delete(opal_tsd_key_t key) { return pthread_key_delete(key); } -static inline int -opal_tsd_setspecific(opal_tsd_key_t key, void *value) +static inline int opal_tsd_setspecific(opal_tsd_key_t key, void *value) { return pthread_setspecific(key, value); } -static inline int -opal_tsd_getspecific(opal_tsd_key_t key, void **valuep) +static inline int opal_tsd_getspecific(opal_tsd_key_t key, void **valuep) { *valuep = pthread_getspecific(key); return OPAL_SUCCESS; diff --git a/opal/mca/threads/pthreads/threads_pthreads_wait_sync.c b/opal/mca/threads/pthreads/threads_pthreads_wait_sync.c index 21a8943c5d7..622efdfe1df 100644 --- a/opal/mca/threads/pthreads/threads_pthreads_wait_sync.c +++ b/opal/mca/threads/pthreads/threads_pthreads_wait_sync.c @@ -14,19 +14,20 @@ * * $HEADER$ */ + #include "opal/mca/threads/wait_sync.h" static opal_mutex_t wait_sync_lock = OPAL_MUTEX_STATIC_INIT; -static ompi_wait_sync_t* wait_sync_list = NULL; +static ompi_wait_sync_t *wait_sync_list = NULL; static opal_atomic_int32_t num_thread_in_progress = 0; -#define WAIT_SYNC_PASS_OWNERSHIP(who) \ - do { \ - pthread_mutex_lock( &(who)->lock); \ - pthread_cond_signal( &(who)->condition ); \ - pthread_mutex_unlock( &(who)->lock); \ - } while(0) +#define WAIT_SYNC_PASS_OWNERSHIP(who) \ + do { \ + pthread_mutex_lock(&(who)->lock); \ + pthread_cond_signal(&(who)->condition); \ + pthread_mutex_unlock(&(who)->lock); \ + } while (0) int ompi_sync_wait_mt(ompi_wait_sync_t *sync) { @@ -34,8 +35,9 @@ int ompi_sync_wait_mt(ompi_wait_sync_t *sync) * race condition around the release of the synchronization using the * signaling field. */ - if(sync->count <= 0) + if (sync->count <= 0) { return (0 == sync->status) ? OPAL_SUCCESS : OPAL_ERROR; + } /* lock so nobody can signal us during the list updating */ pthread_mutex_lock(&sync->lock); @@ -43,14 +45,14 @@ int ompi_sync_wait_mt(ompi_wait_sync_t *sync) /* Now that we hold the lock make sure another thread has not already * call cond_signal. */ - if(sync->count <= 0) { + if (sync->count <= 0) { pthread_mutex_unlock(&sync->lock); return (0 == sync->status) ? OPAL_SUCCESS : OPAL_ERROR; } /* Insert sync on the list of pending synchronization constructs */ OPAL_THREAD_LOCK(&wait_sync_lock); - if( NULL == wait_sync_list ) { + if (NULL == wait_sync_list) { sync->next = sync->prev = sync; wait_sync_list = sync; } else { @@ -62,12 +64,14 @@ int ompi_sync_wait_mt(ompi_wait_sync_t *sync) OPAL_THREAD_UNLOCK(&wait_sync_lock); /** - * If we are not responsible for progresing, go silent until something worth noticing happen: + * If we are not responsible for progressing, go silent until something + * worth noticing happen: * - this thread has been promoted to take care of the progress * - our sync has been triggered. */ - check_status: - if( sync != wait_sync_list && num_thread_in_progress >= opal_max_thread_in_progress) { + check_status: + if (sync != wait_sync_list && + num_thread_in_progress >= opal_max_thread_in_progress) { pthread_cond_wait(&sync->condition, &sync->lock); /** @@ -76,7 +80,7 @@ int ompi_sync_wait_mt(ompi_wait_sync_t *sync) * promoted as the progress manager. */ - if( sync->count <= 0 ) { /* Completed? */ + if (sync->count <= 0) { /* Completed? */ pthread_mutex_unlock(&sync->lock); goto i_am_done; } @@ -86,21 +90,23 @@ int ompi_sync_wait_mt(ompi_wait_sync_t *sync) pthread_mutex_unlock(&sync->lock); OPAL_THREAD_ADD_FETCH32(&num_thread_in_progress, 1); - while(sync->count > 0) { /* progress till completion */ - opal_progress(); /* don't progress with the sync lock locked or you'll deadlock */ + while (sync->count > 0) { /* progress till completion */ + /* don't progress with the sync lock locked or you'll deadlock */ + opal_progress(); } OPAL_THREAD_ADD_FETCH32(&num_thread_in_progress, -1); - i_am_done: + i_am_done: /* My sync is now complete. Trim the list: remove self, wake next */ OPAL_THREAD_LOCK(&wait_sync_lock); sync->prev->next = sync->next; sync->next->prev = sync->prev; /* In case I am the progress manager, pass the duties on */ - if( sync == wait_sync_list ) { + if (sync == wait_sync_list) { wait_sync_list = (sync == sync->next) ? NULL : sync->next; - if( NULL != wait_sync_list ) + if (NULL != wait_sync_list) { WAIT_SYNC_PASS_OWNERSHIP(wait_sync_list); + } } OPAL_THREAD_UNLOCK(&wait_sync_lock); diff --git a/opal/mca/threads/pthreads/threads_pthreads_wait_sync.h b/opal/mca/threads/pthreads/threads_pthreads_wait_sync.h index 26a1a3927f4..d34b9fcd3c7 100644 --- a/opal/mca/threads/pthreads/threads_pthreads_wait_sync.h +++ b/opal/mca/threads/pthreads/threads_pthreads_wait_sync.h @@ -24,8 +24,8 @@ */ -#ifndef OPAL_MCA_THREADS_PTHREADS_THREADS_PTHREADS_WAIT_SYNC_H -#define OPAL_MCA_THREADS_PTHREADS_THREADS_PTHREADS_WAIT_SYNC_H 1 +#ifndef OPAL_MCA_THREADS_PTHREADS_THREADS_PTHREADS_WAIT_SYNC_H +#define OPAL_MCA_THREADS_PTHREADS_THREADS_PTHREADS_WAIT_SYNC_H typedef struct ompi_wait_sync_t { opal_atomic_int32_t count; @@ -37,7 +37,8 @@ typedef struct ompi_wait_sync_t { volatile bool signaling; } ompi_wait_sync_t; -#define SYNC_WAIT(sync) (opal_using_threads() ? ompi_sync_wait_mt (sync) : sync_wait_st (sync)) +#define SYNC_WAIT(sync) \ + (opal_using_threads() ? ompi_sync_wait_mt(sync) : sync_wait_st(sync)) /* The loop in release handles a race condition between the signaling * thread and the destruction of the condition variable. The signaling @@ -71,21 +72,20 @@ typedef struct ompi_wait_sync_t { sync->signaling = false; \ } -#define WAIT_SYNC_SIGNALLED(sync){ \ +#define WAIT_SYNC_SIGNALLED(sync) \ + { \ (sync)->signaling = false; \ -} + } OPAL_DECLSPEC int ompi_sync_wait_mt(ompi_wait_sync_t *sync); -static inline int sync_wait_st (ompi_wait_sync_t *sync) +static inline int sync_wait_st(ompi_wait_sync_t *sync) { while (sync->count > 0) { opal_progress(); } - return sync->status; } - #define WAIT_SYNC_INIT(sync,c) \ do { \ (sync)->count = (c); \ @@ -94,9 +94,9 @@ static inline int sync_wait_st (ompi_wait_sync_t *sync) (sync)->status = 0; \ (sync)->signaling = (0 != (c)); \ if (opal_using_threads()) { \ - pthread_cond_init (&(sync)->condition, NULL); \ - pthread_mutex_init (&(sync)->lock, NULL); \ + pthread_cond_init(&(sync)->condition, NULL); \ + pthread_mutex_init(&(sync)->lock, NULL); \ } \ - } while(0) + } while (0) #endif /* OPAL_MCA_THREADS_PTHREADS_THREADS_PTHREADS_WAIT_SYNC_H */ diff --git a/opal/mca/threads/qthreads/threads_qthreads_component.c b/opal/mca/threads/qthreads/threads_qthreads_component.c index 86cff6bd762..bae4cc18983 100644 --- a/opal/mca/threads/qthreads/threads_qthreads_component.c +++ b/opal/mca/threads/qthreads/threads_qthreads_component.c @@ -21,13 +21,6 @@ * $HEADER$ */ - * $COPYRIGHT$ - * - * Additional copyrights may follow - * - * $HEADER$ - */ - #include "opal_config.h" #include "opal/mca/threads/thread.h" @@ -38,7 +31,7 @@ static int opal_threads_qthreads_open(void); const opal_threads_base_component_1_0_0_t mca_threads_qthreads_component = { /* First, the mca_component_t struct containing meta information - about the component itself */ + * about the component itself */ .threadsc_version = { OPAL_THREADS_BASE_VERSION_1_0_0, diff --git a/opal/mca/threads/qthreads/threads_qthreads_module.c b/opal/mca/threads/qthreads/threads_qthreads_module.c index 4649447f304..392a73638af 100644 --- a/opal/mca/threads/qthreads/threads_qthreads_module.c +++ b/opal/mca/threads/qthreads/threads_qthreads_module.c @@ -1,3 +1,4 @@ +/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */ /* * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana * University Research and Technology @@ -58,21 +59,21 @@ bool opal_thread_self_compare(opal_thread_t *t) return OPAL_ERROR; } -int sync_wait_mt(void *p) +int sync_wait_mt(void *p) { return OPAL_ERROR; } -int opal_thread_join(opal_thread_t *t, void **thr_return) +int opal_thread_join(opal_thread_t *t, void **thr_return) { return OPAL_ERROR; } -void opal_thread_set_main() +void opal_thread_set_main(void) { } -int opal_thread_start(opal_thread_t *t) +int opal_thread_start(opal_thread_t *t) { return OPAL_ERR_NOT_IMPLEMENTED; } @@ -86,19 +87,5 @@ int opal_tsd_key_create(opal_tsd_key_t *key, opal_tsd_destructor_t destructor) int opal_tsd_keys_destruct(void) { - int i; - void * ptr; - for (i=0; im_lock_pthread, &attr); - pthread_mutexattr_destroy(&attr); - - m->m_lock_debug = 0; - m->m_lock_file = NULL; - m->m_lock_line = 0; -#else - - /* Without debugging, choose the fastest available mutexes */ - pthread_mutex_init(&m->m_lock_pthread, NULL); - -#endif /* OPAL_ENABLE_DEBUG */ - -#if OPAL_HAVE_ATOMIC_SPINLOCKS - opal_atomic_lock_init( &m->m_lock_atomic, OPAL_ATOMIC_LOCK_UNLOCKED ); -#endif } static void opal_mutex_destruct(opal_mutex_t *m) { - pthread_mutex_destroy(&m->m_lock_pthread); } OBJ_CLASS_INSTANCE(opal_mutex_t, @@ -74,23 +48,6 @@ OBJ_CLASS_INSTANCE(opal_mutex_t, static void opal_recursive_mutex_construct(opal_recursive_mutex_t *m) { - pthread_mutexattr_t attr; - pthread_mutexattr_init(&attr); - -#if OPAL_ENABLE_DEBUG - m->m_lock_debug = 0; - m->m_lock_file = NULL; - m->m_lock_line = 0; -#endif - - pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); - - pthread_mutex_init(&m->m_lock_pthread, &attr); - pthread_mutexattr_destroy(&attr); - -#if OPAL_HAVE_ATOMIC_SPINLOCKS - opal_atomic_lock_init( &m->m_lock_atomic, OPAL_ATOMIC_LOCK_UNLOCKED ); -#endif } OBJ_CLASS_INSTANCE(opal_recursive_mutex_t, diff --git a/opal/mca/threads/thread.h b/opal/mca/threads/thread.h index 9bf106a6dc7..9be62eddb96 100644 --- a/opal/mca/threads/thread.h +++ b/opal/mca/threads/thread.h @@ -22,8 +22,8 @@ */ -#ifndef OPAL_MCA_THREADS_THREADS_H -#define OPAL_MCA_THREADS_THREADS_H +#ifndef OPAL_MCA_THREADS_THREAD_H +#define OPAL_MCA_THREADS_THREAD_H #include "opal_config.h" @@ -43,7 +43,8 @@ struct opal_threads_base_component_1_0_0_t { /** * Convenience typedef */ -typedef struct opal_threads_base_component_1_0_0_t opal_threads_base_component_1_0_0_t; +typedef struct opal_threads_base_component_1_0_0_t + opal_threads_base_component_1_0_0_t; /* * Macro for use in components that are of type threads @@ -51,4 +52,4 @@ typedef struct opal_threads_base_component_1_0_0_t opal_threads_base_component_1 #define OPAL_THREADS_BASE_VERSION_1_0_0 \ OPAL_MCA_BASE_VERSION_2_1_0("threads", 1, 0, 0) -#endif /* OPAL_MCA_THREADS_THREADS_H */ +#endif /* OPAL_MCA_THREADS_THREAD_H */ diff --git a/opal/mca/threads/thread_usage.h b/opal/mca/threads/thread_usage.h index 92e0031a751..8c2ec8291d1 100644 --- a/opal/mca/threads/thread_usage.h +++ b/opal/mca/threads/thread_usage.h @@ -6,7 +6,7 @@ * Copyright (c) 2004-2007 The University of Tennessee and The University * of Tennessee Research Foundation. All rights * reserved. - * Copyright (c) 2004-2006 High Performance Computing Center Stuttgart, + * Copyright (c) 2004-2006 High Performance Computing Center Stuttgart, * University of Stuttgart. All rights reserved. * Copyright (c) 2004-2005 The Regents of the University of California. * All rights reserved. @@ -16,15 +16,16 @@ * Copyright (c) 2015-2018 Los Alamos National Security, LLC. All rights * reserved. * Copyright (c) 2019 Sandia National Laboratories. All rights reserved. + * * $COPYRIGHT$ - * + * * Additional copyrights may follow - * + * * $HEADER$ */ -#if !defined(OPAL_MCA_THREAD_USAGE_H) -#define OPAL_MCA_THREAD_USAGE_H +#ifndef OPAL_MCA_THREADS_THREAD_USAGE_H +#define OPAL_MCA_THREADS_THREAD_USAGE_H #include "opal_config.h" @@ -64,7 +65,7 @@ OPAL_DECLSPEC extern bool opal_uses_threads; * possibility that we may have multiple threads, true will be * returned. */ -#define opal_using_threads() opal_uses_threads +#define opal_using_threads() opal_uses_threads /** * Set whether the process is using multiple threads or not. @@ -94,56 +95,62 @@ static inline bool opal_set_using_threads(bool have) * indicates that threads are in use by the application or library. */ -#define OPAL_THREAD_DEFINE_ATOMIC_OP(type, name, operator, suffix) \ -static inline type opal_thread_ ## name ## _fetch_ ## suffix (opal_atomic_ ## type *addr, type delta) \ -{ \ - if (OPAL_UNLIKELY(opal_using_threads())) { \ - return opal_atomic_ ## name ## _fetch_ ## suffix (addr, delta); \ - } \ - \ - *addr = *addr operator delta; \ - return *addr; \ -} \ - \ -static inline type opal_thread_fetch_ ## name ## _ ## suffix (opal_atomic_ ## type *addr, type delta) \ -{ \ - if (OPAL_UNLIKELY(opal_using_threads())) { \ - return opal_atomic_fetch_ ## name ## _ ## suffix (addr, delta); \ - } \ - \ - type old = *addr; \ - *addr = old operator delta; \ - return old; \ +#define OPAL_THREAD_DEFINE_ATOMIC_OP(type, name, operator, suffix) \ +static inline type opal_thread_ ## name ## _fetch_ ## suffix \ + (opal_atomic_ ## type *addr, type delta) \ +{ \ + if (OPAL_UNLIKELY(opal_using_threads())) { \ + return opal_atomic_ ## name ## _fetch_ ## suffix (addr, delta); \ + } \ + \ + *addr = *addr operator delta; \ + return *addr; \ +} \ + \ +static inline type opal_thread_fetch_ ## name ## _ ## suffix \ + (opal_atomic_ ## type *addr, type delta) \ +{ \ + if (OPAL_UNLIKELY(opal_using_threads())) { \ + return opal_atomic_fetch_ ## name ## _ ## suffix (addr, delta); \ + } \ + \ + type old = *addr; \ + *addr = old operator delta; \ + return old; \ } -#define OPAL_THREAD_DEFINE_ATOMIC_COMPARE_EXCHANGE(type, addr_type, suffix) \ -static inline bool opal_thread_compare_exchange_strong_ ## suffix (opal_atomic_ ## addr_type *addr, type *compare, type value) \ -{ \ - if (OPAL_UNLIKELY(opal_using_threads())) { \ - return opal_atomic_compare_exchange_strong_ ## suffix (addr, (addr_type *) compare, (addr_type) value); \ - } \ - \ - if ((type) *addr == *compare) { \ - ((type *) addr)[0] = value; \ - return true; \ - } \ - \ - *compare = ((type *) addr)[0]; \ - \ - return false; \ +#define OPAL_THREAD_DEFINE_ATOMIC_COMPARE_EXCHANGE(type, addr_type, suffix) \ +static inline bool opal_thread_compare_exchange_strong_ ## suffix \ + (opal_atomic_ ## addr_type *addr, type *compare, type value) \ +{ \ + if (OPAL_UNLIKELY(opal_using_threads())) { \ + return opal_atomic_compare_exchange_strong_ ## suffix \ + (addr, (addr_type *)compare, (addr_type)value); \ + } \ + \ + if ((type) *addr == *compare) { \ + ((type *)addr)[0] = value; \ + return true; \ + } \ + \ + *compare = ((type *)addr)[0]; \ + \ + return false; \ } -#define OPAL_THREAD_DEFINE_ATOMIC_SWAP(type, addr_type, suffix) \ -static inline type opal_thread_swap_ ## suffix (opal_atomic_ ## addr_type *ptr, type newvalue) \ -{ \ - if (opal_using_threads ()) { \ - return (type) opal_atomic_swap_ ## suffix (ptr, (addr_type) newvalue); \ - } \ - \ - type old = ((type *) ptr)[0]; \ - ((type *) ptr)[0] = newvalue; \ - \ - return old; \ +#define OPAL_THREAD_DEFINE_ATOMIC_SWAP(type, addr_type, suffix) \ +static inline type opal_thread_swap_ ## suffix \ + (opal_atomic_ ## addr_type *ptr, type newvalue) \ +{ \ + if (opal_using_threads ()) { \ + return (type) opal_atomic_swap_ ## suffix \ + (ptr, (addr_type) newvalue); \ + } \ + \ + type old = ((type *)ptr)[0]; \ + ((type *)ptr)[0] = newvalue; \ + \ + return old; \ } OPAL_THREAD_DEFINE_ATOMIC_OP(int32_t, add, +, 32) @@ -195,16 +202,22 @@ OPAL_THREAD_DEFINE_ATOMIC_SWAP(intptr_t, intptr_t, ptr) #define OPAL_THREAD_FETCH_SUB_SIZE_T opal_thread_fetch_sub_size_t #define OPAL_ATOMIC_FETCH_SUB_SIZE_T opal_thread_fetch_sub_size_t -#define OPAL_THREAD_COMPARE_EXCHANGE_STRONG_32 opal_thread_compare_exchange_strong_32 -#define OPAL_ATOMIC_COMPARE_EXCHANGE_STRONG_32 opal_thread_compare_exchange_strong_32 +#define OPAL_THREAD_COMPARE_EXCHANGE_STRONG_32 \ + opal_thread_compare_exchange_strong_32 +#define OPAL_ATOMIC_COMPARE_EXCHANGE_STRONG_32 \ + opal_thread_compare_exchange_strong_32 -#define OPAL_THREAD_COMPARE_EXCHANGE_STRONG_PTR(x, y, z) opal_thread_compare_exchange_strong_ptr ((opal_atomic_intptr_t *) x, (intptr_t *) y, (intptr_t) z) -#define OPAL_ATOMIC_COMPARE_EXCHANGE_STRONG_PTR OPAL_THREAD_COMPARE_EXCHANGE_STRONG_PTR +#define OPAL_THREAD_COMPARE_EXCHANGE_STRONG_PTR(x, y, z) \ + opal_thread_compare_exchange_strong_ptr ((opal_atomic_intptr_t *) x, \ + (intptr_t *) y, (intptr_t) z) +#define OPAL_ATOMIC_COMPARE_EXCHANGE_STRONG_PTR \ + OPAL_THREAD_COMPARE_EXCHANGE_STRONG_PTR #define OPAL_THREAD_SWAP_32 opal_thread_swap_32 #define OPAL_ATOMIC_SWAP_32 opal_thread_swap_32 -#define OPAL_THREAD_SWAP_PTR(x, y) opal_thread_swap_ptr ((opal_atomic_intptr_t *) x, (intptr_t) y) +#define OPAL_THREAD_SWAP_PTR(x, y) \ + opal_thread_swap_ptr ((opal_atomic_intptr_t *) x, (intptr_t) y) #define OPAL_ATOMIC_SWAP_PTR OPAL_THREAD_SWAP_PTR /* define 64-bit macros is 64-bit atomic math is available */ @@ -242,8 +255,10 @@ OPAL_THREAD_DEFINE_ATOMIC_SWAP(int64_t, int64_t, 64) #define OPAL_THREAD_FETCH_XOR64 opal_thread_fetch_xor_64 #define OPAL_ATOMIC_FETCH_XOR64 opal_thread_fetch_xor_64 -#define OPAL_THREAD_COMPARE_EXCHANGE_STRONG_64 opal_thread_compare_exchange_strong_64 -#define OPAL_ATOMIC_COMPARE_EXCHANGE_STRONG_64 opal_thread_compare_exchange_strong_64 +#define OPAL_THREAD_COMPARE_EXCHANGE_STRONG_64 \ + opal_thread_compare_exchange_strong_64 +#define OPAL_ATOMIC_COMPARE_EXCHANGE_STRONG_64 \ + opal_thread_compare_exchange_strong_64 #define OPAL_THREAD_SWAP_64 opal_thread_swap_64 #define OPAL_ATOMIC_SWAP_64 opal_thread_swap_64 @@ -264,4 +279,4 @@ OPAL_THREAD_DEFINE_ATOMIC_SWAP(int64_t, int64_t, 64) #define OPAL_HAVE_THREAD_LOCAL 0 #endif /* !defined(OPAL_HAVE_THREAD_LOCAL) */ -#endif /* !defined(OPAL_MCA_THREAD_USAGE_H) */ +#endif /* OPAL_MCA_THREADS_THREAD_USAGE_H */ diff --git a/opal/mca/threads/threads.h b/opal/mca/threads/threads.h index b7378e4db61..bcbfa88197d 100644 --- a/opal/mca/threads/threads.h +++ b/opal/mca/threads/threads.h @@ -1,3 +1,4 @@ +/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */ /* * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana * University Research and Technology @@ -15,6 +16,7 @@ * and Technology (RIST). All rights reserved. * Copyright (c) 2017 Intel, Inc. All rights reserved. * Copyright (c) 2019 Sandia National Laboratories. All rights reserved. + * * $COPYRIGHT$ * * Additional copyrights may follow @@ -22,8 +24,8 @@ * $HEADER$ */ -#ifndef OPAL_MCA_THREAD_H -#define OPAL_MCA_THREAD_H 1 +#ifndef OPAL_MCA_THREADS_THREADS_H +#define OPAL_MCA_THREADS_THREADS_H #include "opal_config.h" @@ -37,9 +39,9 @@ BEGIN_C_DECLS -typedef void *(*opal_thread_fn_t) (opal_object_t *); +typedef void *(*opal_thread_fn_t)(opal_object_t *); -#define OPAL_THREAD_CANCELLED ((void*)1); +#define OPAL_THREAD_CANCELLED ((void *)1); #include MCA_threads_base_include_HEADER @@ -70,7 +72,7 @@ OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_thread_t); __FILE__, __LINE__); \ } \ *(act) = true; \ - } while(0); + } while (0); #else #define OPAL_ACQUIRE_THREAD(lck, cnd, act) \ do { \ @@ -79,7 +81,7 @@ OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_thread_t); opal_condition_wait((cnd), (lck)); \ } \ *(act) = true; \ - } while(0); + } while (0); #endif @@ -93,14 +95,14 @@ OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_thread_t); *(act) = false; \ opal_condition_broadcast((cnd)); \ OPAL_THREAD_UNLOCK((lck)); \ - } while(0); + } while (0); #else #define OPAL_RELEASE_THREAD(lck, cnd, act) \ do { \ *(act) = false; \ opal_condition_broadcast((cnd)); \ OPAL_THREAD_UNLOCK((lck)); \ - } while(0); + } while (0); #endif @@ -108,7 +110,7 @@ OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_thread_t); do { \ *(act) = false; \ opal_condition_broadcast((cnd)); \ - } while(0); + } while (0); /* provide a macro for forward-proofing the shifting * of objects between libevent threads - at some point, we @@ -126,7 +128,7 @@ OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_thread_t); OPAL_DECLSPEC int opal_thread_start(opal_thread_t *); OPAL_DECLSPEC int opal_thread_join(opal_thread_t *, void **thread_return); -OPAL_DECLSPEC bool opal_thread_self_compare(opal_thread_t*); +OPAL_DECLSPEC bool opal_thread_self_compare(opal_thread_t *); OPAL_DECLSPEC opal_thread_t *opal_thread_get_self(void); OPAL_DECLSPEC void opal_thread_kill(opal_thread_t *, int sig); OPAL_DECLSPEC void opal_thread_set_main(void); @@ -134,4 +136,4 @@ OPAL_DECLSPEC void opal_event_use_threads(void); END_C_DECLS -#endif /* OPAL_MCA_THREAD_H */ +#endif /* OPAL_MCA_THREADS_THREADS_H */ diff --git a/opal/mca/threads/tsd.h b/opal/mca/threads/tsd.h index 83950da1913..f05d0747a96 100644 --- a/opal/mca/threads/tsd.h +++ b/opal/mca/threads/tsd.h @@ -1,3 +1,4 @@ +/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */ /* * Copyright (c) 2007-2013 Los Alamos National Security, LLC. All rights * reserved. @@ -44,7 +45,7 @@ typedef void (*opal_tsd_destructor_t)(void *value); /** * Typedef for thread-specific data key */ -typedef void* opal_tsd_key_t; +typedef void *opal_tsd_key_t; /** diff --git a/opal/mca/threads/wait_sync.h b/opal/mca/threads/wait_sync.h index 0b5f421c75f..c600a3d0e95 100644 --- a/opal/mca/threads/wait_sync.h +++ b/opal/mca/threads/wait_sync.h @@ -10,6 +10,7 @@ * and Technology (RIST). All rights reserved. * Copyright (c) 2017 IBM Corporation. All rights reserved. * Copyright (c) 2019 Sandia National Laboratories. All rights reserved. + * * $COPYRIGHT$ * * Additional copyrights may follow @@ -17,7 +18,7 @@ * $HEADER$ */ -#if !defined(OPAL_MCA_THREADS_WAIT_SYNC_H) +#ifndef OPAL_MCA_THREADS_WAIT_SYNC_H #define OPAL_MCA_THREADS_WAIT_SYNC_H #include "opal/sys/atomic.h" @@ -29,8 +30,8 @@ extern int opal_max_thread_in_progress; #include MCA_threads_wait_sync_base_include_HEADER -#define REQUEST_PENDING (void*)0L -#define REQUEST_COMPLETED (void*)1L +#define REQUEST_PENDING (void *)0L +#define REQUEST_COMPLETED (void *)1L /** * Update the status of the synchronization primitive. If an error is @@ -38,21 +39,22 @@ extern int opal_max_thread_in_progress; * triggered. The status of the synchronization will be reported to * the waiting threads. */ -static inline void wait_sync_update(ompi_wait_sync_t *sync, int updates, int status) +static inline void wait_sync_update(ompi_wait_sync_t *sync, int updates, + int status) { - if( OPAL_LIKELY(OPAL_SUCCESS == status) ) { - if( 0 != (OPAL_THREAD_ADD_FETCH32(&sync->count, -updates)) ) { + if (OPAL_LIKELY(OPAL_SUCCESS == status)) { + if (0 != (OPAL_THREAD_ADD_FETCH32(&sync->count, -updates))) { return; } } else { /* this is an error path so just use the atomic */ sync->status = OPAL_ERROR; - opal_atomic_wmb (); - opal_atomic_swap_32 (&sync->count, 0); + opal_atomic_wmb(); + opal_atomic_swap_32(&sync->count, 0); } WAIT_SYNC_SIGNAL(sync); } END_C_DECLS -#endif /* defined(OPAL_MCA_THREADS_WAIT_SYNC_H) */ +#endif /* OPAL_MCA_THREADS_WAIT_SYNC_H */