root/opal/mca/pmix/pmix4x/pmix/examples/examples.h

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

INCLUDED FROM


   1 /*
   2  * Copyright (c) 2004-2010 The Trustees of Indiana University and Indiana
   3  *                         University Research and Technology
   4  *                         Corporation.  All rights reserved.
   5  * Copyright (c) 2004-2011 The University of Tennessee and The University
   6  *                         of Tennessee Research Foundation.  All rights
   7  *                         reserved.
   8  * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
   9  *                         University of Stuttgart.  All rights reserved.
  10  * Copyright (c) 2004-2005 The Regents of the University of California.
  11  *                         All rights reserved.
  12  * Copyright (c) 2006-2013 Los Alamos National Security, LLC.
  13  *                         All rights reserved.
  14  * Copyright (c) 2009-2012 Cisco Systems, Inc.  All rights reserved.
  15  * Copyright (c) 2011      Oak Ridge National Labs.  All rights reserved.
  16  * Copyright (c) 2013-2019 Intel, Inc.  All rights reserved.
  17  * Copyright (c) 2015      Mellanox Technologies, Inc.  All rights reserved.
  18  * $COPYRIGHT$
  19  *
  20  * Additional copyrights may follow
  21  *
  22  * $HEADER$
  23  *
  24  */
  25 
  26 #define _GNU_SOURCE
  27 #include <stdio.h>
  28 #include <stdlib.h>
  29 #include <unistd.h>
  30 #include <time.h>
  31 #include <pthread.h>
  32 
  33 #include <pmix_common.h>
  34 
  35 typedef struct {
  36     pthread_mutex_t mutex;
  37     pthread_cond_t cond;
  38     volatile bool active;
  39     pmix_status_t status;
  40     int count;
  41     size_t evhandler_ref;
  42 } mylock_t;
  43 
  44 #define DEBUG_CONSTRUCT_LOCK(l)                     \
  45     do {                                            \
  46         pthread_mutex_init(&(l)->mutex, NULL);      \
  47         pthread_cond_init(&(l)->cond, NULL);        \
  48         (l)->active = true;                         \
  49         (l)->status = PMIX_SUCCESS;                 \
  50         (l)->count = 0;                             \
  51         (l)->evhandler_ref = 0;                     \
  52     } while(0)
  53 
  54 #define DEBUG_DESTRUCT_LOCK(l)              \
  55     do {                                    \
  56         pthread_mutex_destroy(&(l)->mutex); \
  57         pthread_cond_destroy(&(l)->cond);   \
  58     } while(0)
  59 
  60 #define DEBUG_WAIT_THREAD(lck)                                      \
  61     do {                                                            \
  62         pthread_mutex_lock(&(lck)->mutex);                          \
  63         while ((lck)->active) {                                     \
  64             pthread_cond_wait(&(lck)->cond, &(lck)->mutex);         \
  65         }                                                           \
  66         pthread_mutex_unlock(&(lck)->mutex);                        \
  67     } while(0)
  68 
  69 #define DEBUG_WAKEUP_THREAD(lck)                        \
  70     do {                                                \
  71         pthread_mutex_lock(&(lck)->mutex);              \
  72         (lck)->active = false;                          \
  73         pthread_cond_broadcast(&(lck)->cond);           \
  74         pthread_mutex_unlock(&(lck)->mutex);            \
  75     } while(0)
  76 
  77 /* define a structure for collecting returned
  78  * info from a query */
  79 typedef struct {
  80     mylock_t lock;
  81     pmix_info_t *info;
  82     size_t ninfo;
  83 } myquery_data_t;
  84 
  85 #define DEBUG_CONSTRUCT_MYQUERY(q)                  \
  86     do {                                            \
  87         DEBUG_CONSTRUCT_LOCK(&((q)->lock));         \
  88         (q)->info = NULL;                           \
  89         (q)->ninfo = 0;                             \
  90     } while(0)
  91 
  92 #define DEBUG_DESTRUCT_MYQUERY(q)                   \
  93     do {                                            \
  94         DEBUG_DESTRUCT_LOCK(&((q)->lock));          \
  95         if (NULL != (q)->info) {                    \
  96             PMIX_INFO_FREE((q)->info, (q)->ninfo);  \
  97         }                                           \
  98     } while(0)
  99 
 100 /* define a structure for releasing when a given
 101  * nspace terminates */
 102 typedef struct {
 103     mylock_t lock;
 104     char *nspace;
 105     int exit_code;
 106     bool exit_code_given;
 107 } myrel_t;
 108 
 109 
 110 #define DEBUG_CONSTRUCT_MYREL(r)                \
 111     do {                                        \
 112         DEBUG_CONSTRUCT_LOCK(&((r)->lock));     \
 113         (r)->nspace = NULL;                     \
 114         (r)->exit_code = 0;                     \
 115         (r)->exit_code_given = false;           \
 116     } while(0)
 117 
 118 #define DEBUG_DESTRUCT_MYREL(r)                 \
 119     do {                                        \
 120         DEBUG_DESTRUCT_LOCK(&((r)->lock));      \
 121         if (NULL != (r)->nspace) {              \
 122             free((r)->nspace);                  \
 123         }                                       \
 124     } while(0)

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