This source file includes following definitions.
- mca_allocator_bucket_finalize
- mca_allocator_bucket_module_init
- mca_allocator_bucket_module_register
- mca_allocator_bucket_module_open
- mca_allocator_bucket_module_close
- mca_allocator_bucket_alloc_wrapper
   1 
   2 
   3 
   4 
   5 
   6 
   7 
   8 
   9 
  10 
  11 
  12 
  13 
  14 
  15 
  16 
  17 
  18 
  19 
  20 
  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   
 124 
 125 
 126   {
 127     MCA_ALLOCATOR_BASE_VERSION_2_0_0,
 128 
 129     "bucket", 
 130     OPAL_MAJOR_VERSION,
 131     OPAL_MINOR_VERSION,
 132     OPAL_RELEASE_VERSION,
 133     mca_allocator_bucket_module_open,  
 134     mca_allocator_bucket_module_close, 
 135     NULL,
 136     mca_allocator_bucket_module_register
 137   },
 138   {
 139       
 140       MCA_BASE_METADATA_PARAM_CHECKPOINT
 141   },
 142   mca_allocator_bucket_module_init
 143 };
 144