root/opal/mca/allocator/bucket/allocator_bucket.c

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

DEFINITIONS

This source file includes following definitions.
  1. mca_allocator_bucket_finalize
  2. mca_allocator_bucket_module_init
  3. mca_allocator_bucket_module_register
  4. mca_allocator_bucket_module_open
  5. mca_allocator_bucket_module_close
  6. mca_allocator_bucket_alloc_wrapper

   1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
   2 /*
   3  * Copyright (c) 2004-2007 The Trustees of Indiana University and Indiana
   4  *                         University Research and Technology
   5  *                         Corporation.  All rights reserved.
   6  * Copyright (c) 2004-2005 The University of Tennessee and The University
   7  *                         of Tennessee Research Foundation.  All rights
   8  *                         reserved.
   9  * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
  10  *                         University of Stuttgart.  All rights reserved.
  11  * Copyright (c) 2004-2005 The Regents of the University of California.
  12  *                         All rights reserved.
  13  * Copyright (c) 2008      Cisco Systems, Inc.  All rights reserved.
  14  * Copyright (c) 2014      Los Alamos National Security, LLC. All rights
  15  *                         reseved.
  16  * $COPYRIGHT$
  17  *
  18  * Additional copyrights may follow
  19  *
  20  * $HEADER$
  21  */
  22 
  23 #include "opal_config.h"
  24 #include "opal/mca/allocator/allocator.h"
  25 #include "opal/constants.h"
  26 #include "opal/mca/allocator/bucket/allocator_bucket_alloc.h"
  27 #include "opal/mca/base/mca_base_var.h"
  28 
  29 struct mca_allocator_base_module_t* mca_allocator_bucket_module_init(
  30     bool enable_mpi_threads,
  31     mca_allocator_base_component_segment_alloc_fn_t segment_alloc,
  32     mca_allocator_base_component_segment_free_fn_t segment_free,
  33     void *context);
  34 
  35 int mca_allocator_bucket_module_open(void);
  36 
  37 int mca_allocator_bucket_module_close(void);
  38 
  39 void * mca_allocator_bucket_alloc_wrapper(
  40     struct mca_allocator_base_module_t* allocator,
  41     size_t size, size_t align);
  42 
  43 static int mca_allocator_num_buckets;
  44 
  45 
  46 
  47 int mca_allocator_bucket_finalize(struct mca_allocator_base_module_t* allocator)
  48 {
  49     mca_allocator_bucket_t *bucket = (mca_allocator_bucket_t *) allocator;
  50 
  51     mca_allocator_bucket_cleanup(allocator);
  52 
  53     for (int i = 0 ; i < bucket->num_buckets ; ++i) {
  54         OBJ_DESTRUCT(&bucket->buckets[i].lock);
  55     }
  56 
  57     free (bucket->buckets);
  58     free(allocator);
  59 
  60     return(OPAL_SUCCESS);
  61 }
  62 
  63 struct mca_allocator_base_module_t* mca_allocator_bucket_module_init(
  64     bool enable_mpi_threads,
  65     mca_allocator_base_component_segment_alloc_fn_t segment_alloc,
  66     mca_allocator_base_component_segment_free_fn_t segment_free,
  67     void *context)
  68 {
  69     size_t alloc_size = sizeof(mca_allocator_bucket_t);
  70     mca_allocator_bucket_t * retval;
  71     mca_allocator_bucket_t * allocator = (mca_allocator_bucket_t *) malloc(alloc_size);
  72     if(NULL == allocator) {
  73         return NULL;
  74     }
  75     retval = mca_allocator_bucket_init((mca_allocator_base_module_t *) allocator,
  76         mca_allocator_num_buckets,
  77         segment_alloc,
  78         segment_free);
  79     if(NULL == retval) {
  80         free(allocator);
  81         return NULL;
  82     }
  83     allocator->super.alc_alloc =  mca_allocator_bucket_alloc_wrapper;
  84     allocator->super.alc_realloc = mca_allocator_bucket_realloc;
  85     allocator->super.alc_free =  mca_allocator_bucket_free;
  86     allocator->super.alc_compact = mca_allocator_bucket_cleanup;
  87     allocator->super.alc_finalize = mca_allocator_bucket_finalize;
  88     allocator->super.alc_context = context;
  89     return (mca_allocator_base_module_t *) allocator;
  90 }
  91 
  92 static int mca_allocator_bucket_module_register(void) {
  93     mca_allocator_num_buckets = 30;
  94     (void) mca_base_component_var_register(&mca_allocator_bucket_component.allocator_version,
  95                                            "num_buckets", NULL, MCA_BASE_VAR_TYPE_INT, NULL, 0,
  96                                            MCA_BASE_VAR_FLAG_SETTABLE, OPAL_INFO_LVL_9,
  97                                            MCA_BASE_VAR_SCOPE_LOCAL, &mca_allocator_num_buckets);
  98     return OPAL_SUCCESS;
  99 }
 100 
 101 int mca_allocator_bucket_module_open(void) {
 102     return OPAL_SUCCESS;
 103 }
 104 
 105 int mca_allocator_bucket_module_close(void) {
 106     return OPAL_SUCCESS;
 107 }
 108 
 109 void * mca_allocator_bucket_alloc_wrapper(
 110     struct mca_allocator_base_module_t* allocator,
 111     size_t size,
 112     size_t align)
 113 {
 114     if(0 == align){
 115         return mca_allocator_bucket_alloc(allocator, size);
 116     }
 117     return mca_allocator_bucket_alloc_align(allocator, size, align);
 118 }
 119 
 120 
 121 mca_allocator_base_component_t mca_allocator_bucket_component = {
 122 
 123   /* First, the mca_base_module_t struct containing meta information
 124      about the module itself */
 125 
 126   {
 127     MCA_ALLOCATOR_BASE_VERSION_2_0_0,
 128 
 129     "bucket", /* MCA module name */
 130     OPAL_MAJOR_VERSION,
 131     OPAL_MINOR_VERSION,
 132     OPAL_RELEASE_VERSION,
 133     mca_allocator_bucket_module_open,  /* module open */
 134     mca_allocator_bucket_module_close, /* module close */
 135     NULL,
 136     mca_allocator_bucket_module_register
 137   },
 138   {
 139       /* The component is checkpoint ready */
 140       MCA_BASE_METADATA_PARAM_CHECKPOINT
 141   },
 142   mca_allocator_bucket_module_init
 143 };
 144 

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