root/opal/mca/pmix/base/base.h

/* [<][>][^][v][top][bottom][index][help] */

INCLUDED FROM


   1 /*
   2  * Copyright (c) 2014-2018 Intel, Inc. All rights reserved.
   3  * $COPYRIGHT$
   4  *
   5  * Additional copyrights may follow
   6  *
   7  * $HEADER$
   8  */
   9 /** @file:
  10  */
  11 
  12 #ifndef MCA_PMI_BASE_H
  13 #define MCA_PMI_BASE_H
  14 
  15 #include "opal_config.h"
  16 #include "opal/types.h"
  17 #include "opal/threads/threads.h"
  18 #include "opal/mca/mca.h"
  19 #include "opal/mca/base/mca_base_framework.h"
  20 
  21 #include "opal/mca/pmix/pmix_types.h"
  22 #include "opal/mca/pmix/pmix.h"
  23 
  24 BEGIN_C_DECLS
  25 
  26 OPAL_DECLSPEC extern mca_base_framework_t opal_pmix_base_framework;
  27 
  28 /**
  29  * Select a pmix module
  30  */
  31 OPAL_DECLSPEC int opal_pmix_base_select(void);
  32 
  33 OPAL_DECLSPEC extern bool opal_pmix_base_allow_delayed_server;
  34 
  35 OPAL_DECLSPEC void opal_pmix_base_register_handler(opal_list_t *event_codes,
  36                                                    opal_list_t *info,
  37                                                    opal_pmix_notification_fn_t evhandler,
  38                                                    opal_pmix_evhandler_reg_cbfunc_t cbfunc,
  39                                                    void *cbdata);
  40 OPAL_DECLSPEC void opal_pmix_base_deregister_handler(size_t errhandler,
  41                                                      opal_pmix_op_cbfunc_t cbfunc,
  42                                                      void *cbdata);
  43 OPAL_DECLSPEC int opal_pmix_base_notify_event(int status,
  44                                               const opal_process_name_t *source,
  45                                               opal_pmix_data_range_t range,
  46                                               opal_list_t *info,
  47                                               opal_pmix_op_cbfunc_t cbfunc, void *cbdata);
  48 OPAL_DECLSPEC void opal_pmix_base_evhandler(int status,
  49                                             const opal_process_name_t *source,
  50                                             opal_list_t *info, opal_list_t *results,
  51                                             opal_pmix_notification_complete_fn_t cbfunc, void *cbdata);
  52 OPAL_DECLSPEC int opal_pmix_base_exchange(opal_value_t *info,
  53                                           opal_pmix_pdata_t *pdat,
  54                                           int timeout);
  55 
  56 OPAL_DECLSPEC void opal_pmix_base_set_evbase(opal_event_base_t *evbase);
  57 
  58 #define opal_pmix_condition_wait(a,b)   pthread_cond_wait(a, &(b)->m_lock_pthread)
  59 typedef pthread_cond_t opal_pmix_condition_t;
  60 #define opal_pmix_condition_broadcast(a) pthread_cond_broadcast(a)
  61 #define opal_pmix_condition_signal(a)    pthread_cond_signal(a)
  62 #define OPAL_PMIX_CONDITION_STATIC_INIT PTHREAD_COND_INITIALIZER
  63 
  64 typedef struct {
  65     opal_mutex_t mutex;
  66     opal_pmix_condition_t cond;
  67     volatile bool active;
  68     int status;
  69 } opal_pmix_lock_t;
  70 
  71 
  72 typedef struct {
  73     opal_event_base_t *evbase;
  74     int timeout;
  75     int initialized;
  76     opal_pmix_lock_t lock;
  77 } opal_pmix_base_t;
  78 
  79 extern opal_pmix_base_t opal_pmix_base;
  80 
  81 #define OPAL_PMIX_CONSTRUCT_LOCK(l)                     \
  82     do {                                                \
  83         OBJ_CONSTRUCT(&(l)->mutex, opal_mutex_t);       \
  84         pthread_cond_init(&(l)->cond, NULL);            \
  85         (l)->active = true;                             \
  86         OPAL_POST_OBJECT((l));                          \
  87     } while(0)
  88 
  89 #define OPAL_PMIX_DESTRUCT_LOCK(l)          \
  90     do {                                    \
  91         OPAL_ACQUIRE_OBJECT((l));           \
  92         OBJ_DESTRUCT(&(l)->mutex);          \
  93         pthread_cond_destroy(&(l)->cond);   \
  94     } while(0)
  95 
  96 
  97 #if OPAL_ENABLE_DEBUG
  98 #define OPAL_PMIX_ACQUIRE_THREAD(lck)                               \
  99     do {                                                            \
 100         opal_mutex_lock(&(lck)->mutex);                             \
 101         if (opal_debug_threads) {                                   \
 102             opal_output(0, "Waiting for thread %s:%d",              \
 103                         __FILE__, __LINE__);                        \
 104         }                                                           \
 105         while ((lck)->active) {                                     \
 106             opal_pmix_condition_wait(&(lck)->cond, &(lck)->mutex);  \
 107         }                                                           \
 108         if (opal_debug_threads) {                                   \
 109             opal_output(0, "Thread obtained %s:%d",                 \
 110                         __FILE__, __LINE__);                        \
 111         }                                                           \
 112         (lck)->active = true;                                       \
 113     } while(0)
 114 #else
 115 #define OPAL_PMIX_ACQUIRE_THREAD(lck)                               \
 116     do {                                                            \
 117         opal_mutex_lock(&(lck)->mutex);                             \
 118         while ((lck)->active) {                                     \
 119             opal_pmix_condition_wait(&(lck)->cond, &(lck)->mutex);  \
 120         }                                                           \
 121         (lck)->active = true;                                       \
 122     } while(0)
 123 #endif
 124 
 125 
 126 #if OPAL_ENABLE_DEBUG
 127 #define OPAL_PMIX_WAIT_THREAD(lck)                                  \
 128     do {                                                            \
 129         opal_mutex_lock(&(lck)->mutex);                             \
 130         if (opal_debug_threads) {                                   \
 131             opal_output(0, "Waiting for thread %s:%d",              \
 132                         __FILE__, __LINE__);                        \
 133         }                                                           \
 134         while ((lck)->active) {                                     \
 135             opal_pmix_condition_wait(&(lck)->cond, &(lck)->mutex);  \
 136         }                                                           \
 137         if (opal_debug_threads) {                                   \
 138             opal_output(0, "Thread obtained %s:%d",                 \
 139                         __FILE__, __LINE__);                        \
 140         }                                                           \
 141         OPAL_ACQUIRE_OBJECT(&lck);                                  \
 142         opal_mutex_unlock(&(lck)->mutex);                           \
 143     } while(0)
 144 #else
 145 #define OPAL_PMIX_WAIT_THREAD(lck)                                  \
 146     do {                                                            \
 147         opal_mutex_lock(&(lck)->mutex);                             \
 148         while ((lck)->active) {                                     \
 149             opal_pmix_condition_wait(&(lck)->cond, &(lck)->mutex);  \
 150         }                                                           \
 151         OPAL_ACQUIRE_OBJECT(lck);                                   \
 152         opal_mutex_unlock(&(lck)->mutex);                           \
 153     } while(0)
 154 #endif
 155 
 156 
 157 #if OPAL_ENABLE_DEBUG
 158 #define OPAL_PMIX_RELEASE_THREAD(lck)                   \
 159     do {                                                \
 160         if (opal_debug_threads) {                       \
 161             opal_output(0, "Releasing thread %s:%d",    \
 162                         __FILE__, __LINE__);            \
 163         }                                               \
 164         (lck)->active = false;                          \
 165         opal_pmix_condition_broadcast(&(lck)->cond);    \
 166         opal_mutex_unlock(&(lck)->mutex);               \
 167     } while(0)
 168 #else
 169 #define OPAL_PMIX_RELEASE_THREAD(lck)                   \
 170     do {                                                \
 171         assert(0 != opal_mutex_trylock(&(lck)->mutex)); \
 172         (lck)->active = false;                          \
 173         opal_pmix_condition_broadcast(&(lck)->cond);    \
 174         opal_mutex_unlock(&(lck)->mutex);               \
 175     } while(0)
 176 #endif
 177 
 178 
 179 #define OPAL_PMIX_WAKEUP_THREAD(lck)                    \
 180     do {                                                \
 181         opal_mutex_lock(&(lck)->mutex);                 \
 182         (lck)->active = false;                          \
 183         OPAL_POST_OBJECT(lck);                          \
 184         opal_pmix_condition_broadcast(&(lck)->cond);    \
 185         opal_mutex_unlock(&(lck)->mutex);               \
 186     } while(0)
 187 
 188 END_C_DECLS
 189 
 190 #endif

/* [<][>][^][v][top][bottom][index][help] */