root/opal/mca/btl/template/btl_template_proc.c

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

DEFINITIONS

This source file includes following definitions.
  1. mca_btl_template_proc_construct
  2. mca_btl_template_proc_destruct
  3. mca_btl_template_proc_lookup_opal
  4. mca_btl_template_proc_create
  5. mca_btl_template_proc_insert

   1 /*
   2  * Copyright (c) 2004-2005 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$
  13  *
  14  * Additional copyrights may follow
  15  *
  16  * $HEADER$
  17  */
  18 
  19 #include "opal_config.h"
  20 
  21 
  22 #include "btl_template.h"
  23 #include "btl_template_proc.h"
  24 
  25 static void mca_btl_template_proc_construct(mca_btl_template_proc_t* proc);
  26 static void mca_btl_template_proc_destruct(mca_btl_template_proc_t* proc);
  27 
  28 OBJ_CLASS_INSTANCE(mca_btl_template_proc_t,
  29         opal_list_item_t, mca_btl_template_proc_construct,
  30         mca_btl_template_proc_destruct);
  31 
  32 void mca_btl_template_proc_construct(mca_btl_template_proc_t* template_proc)
  33 {
  34     template_proc->proc_opal = 0;
  35     template_proc->proc_addr_count = 0;
  36     template_proc->proc_endpoints = 0;
  37     template_proc->proc_endpoint_count = 0;
  38     OBJ_CONSTRUCT(&template_proc->proc_lock, opal_mutex_t);
  39     /* add to list of all proc instance */
  40     OPAL_THREAD_LOCK(&mca_btl_template_component.template_lock);
  41     opal_list_append(&mca_btl_template_component.template_procs, &template_proc->super);
  42     OPAL_THREAD_UNLOCK(&mca_btl_template_component.template_lock);
  43 }
  44 
  45 /*
  46  * Cleanup ib proc instance
  47  */
  48 
  49 void mca_btl_template_proc_destruct(mca_btl_template_proc_t* template_proc)
  50 {
  51     /* remove from list of all proc instances */
  52     OPAL_THREAD_LOCK(&mca_btl_template_component.template_lock);
  53     opal_list_remove_item(&mca_btl_template_component.template_procs,
  54                           &template_proc->super);
  55     OPAL_THREAD_UNLOCK(&mca_btl_template_component.template_lock);
  56 
  57     /* release resources */
  58     if(NULL != template_proc->proc_endpoints) {
  59         free(template_proc->proc_endpoints);
  60     }
  61     OBJ_DESTRUCT(&template_proc->proc_lock);
  62 }
  63 
  64 
  65 /*
  66  * Look for an existing TEMPLATE process instances based on the associated
  67  * opal_proc_t instance.
  68  */
  69 static mca_btl_template_proc_t* mca_btl_template_proc_lookup_opal(opal_proc_t* opal_proc)
  70 {
  71     mca_btl_template_proc_t* template_proc;
  72 
  73     OPAL_THREAD_LOCK(&mca_btl_template_component.template_lock);
  74 
  75     for(template_proc = (mca_btl_template_proc_t*)
  76             opal_list_get_first(&mca_btl_template_component.template_procs);
  77             template_proc != (mca_btl_template_proc_t*)
  78             opal_list_get_end(&mca_btl_template_component.template_procs);
  79             template_proc  = (mca_btl_template_proc_t*)opal_list_get_next(template_proc)) {
  80 
  81         if(template_proc->proc_opal == opal_proc) {
  82             OPAL_THREAD_UNLOCK(&mca_btl_template_component.template_lock);
  83             return template_proc;
  84         }
  85 
  86     }
  87 
  88     OPAL_THREAD_UNLOCK(&mca_btl_template_component.template_lock);
  89 
  90     return NULL;
  91 }
  92 
  93 /*
  94  * Create a TEMPLATE process structure. There is a one-to-one correspondence
  95  * between a opal_proc_t and a mca_btl_template_proc_t instance. We cache
  96  * additional data (specifically the list of mca_btl_template_endpoint_t instances,
  97  * and published addresses) associated w/ a given destination on this
  98  * datastructure.
  99  */
 100 
 101 mca_btl_template_proc_t* mca_btl_template_proc_create(opal_proc_t* opal_proc)
 102 {
 103     mca_btl_template_proc_t* module_proc = NULL;
 104 
 105     /* Check if we have already created a TEMPLATE proc
 106      * structure for this process */
 107     module_proc = mca_btl_template_proc_lookup_opal(opal_proc);
 108 
 109     if(module_proc != NULL) {
 110 
 111         /* Gotcha! */
 112         return module_proc;
 113     }
 114 
 115     /* Oops! First time, gotta create a new TEMPLATE proc
 116      * out of the opal_proc ... */
 117 
 118     module_proc = OBJ_NEW(mca_btl_template_proc_t);
 119 
 120     /* Initialize number of peer */
 121     module_proc->proc_endpoint_count = 0;
 122 
 123     module_proc->proc_opal = opal_proc;
 124 
 125     /* TEMPLATE module doesn't have addresses exported at
 126      * initialization, so the addr_count is set to one. */
 127     module_proc->proc_addr_count = 1;
 128 
 129     /* XXX: Right now, there can be only 1 peer associated
 130      * with a proc. Needs a little bit change in
 131      * mca_btl_template_proc_t to allow on demand increasing of
 132      * number of endpoints for this proc */
 133 
 134     module_proc->proc_endpoints = (mca_btl_base_endpoint_t**)
 135         malloc(module_proc->proc_addr_count * sizeof(mca_btl_base_endpoint_t*));
 136 
 137     if(NULL == module_proc->proc_endpoints) {
 138         OBJ_RELEASE(module_proc);
 139         return NULL;
 140     }
 141     return module_proc;
 142 }
 143 
 144 
 145 /*
 146  * Note that this routine must be called with the lock on the process
 147  * already held.  Insert a btl instance into the proc array and assign
 148  * it an address.
 149  */
 150 int mca_btl_template_proc_insert(mca_btl_template_proc_t* module_proc,
 151         mca_btl_base_endpoint_t* module_endpoint)
 152 {
 153     /* insert into endpoint array */
 154     module_endpoint->endpoint_proc = module_proc;
 155     module_proc->proc_endpoints[module_proc->proc_endpoint_count++] = module_endpoint;
 156 
 157     return OPAL_SUCCESS;
 158 }

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