root/opal/mca/pmix/pmix4x/pmix/src/class/pmix_value_array.c

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

DEFINITIONS

This source file includes following definitions.
  1. pmix_value_array_construct
  2. pmix_value_array_destruct
  3. pmix_value_array_set_size

   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-2005 The University of Tennessee and The University
   6  *                         of Tennessee Research Foundation.  All rights
   7  *                         reserved.
   8  * Copyright (c) 2004-2007 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) 2016-2017 Intel, Inc. All rights reserved.
  13  * $COPYRIGHT$
  14  *
  15  * Additional copyrights may follow
  16  *
  17  * $HEADER$
  18  */
  19 
  20 #include <src/include/pmix_config.h>
  21 
  22 #include "src/class/pmix_value_array.h"
  23 
  24 
  25 static void pmix_value_array_construct(pmix_value_array_t* array)
  26 {
  27     array->array_items = NULL;
  28     array->array_size = 0;
  29     array->array_item_sizeof = 0;
  30     array->array_alloc_size = 0;
  31 }
  32 
  33 static void pmix_value_array_destruct(pmix_value_array_t* array)
  34 {
  35     if (NULL != array->array_items)
  36         free(array->array_items);
  37 }
  38 
  39 PMIX_CLASS_INSTANCE(
  40     pmix_value_array_t,
  41     pmix_object_t,
  42     pmix_value_array_construct,
  43     pmix_value_array_destruct
  44 );
  45 
  46 
  47 int pmix_value_array_set_size(pmix_value_array_t* array, size_t size)
  48 {
  49 #if PMIX_ENABLE_DEBUG
  50     if(array->array_item_sizeof == 0) {
  51         pmix_output(0, "pmix_value_array_set_size: item size must be initialized");
  52         return PMIX_ERR_BAD_PARAM;
  53     }
  54 #endif
  55 
  56     if(size > array->array_alloc_size) {
  57         while(array->array_alloc_size < size)
  58             array->array_alloc_size <<= 1;
  59         array->array_items = (unsigned char *)realloc(array->array_items,
  60             array->array_alloc_size * array->array_item_sizeof);
  61         if (NULL == array->array_items)
  62             return PMIX_ERR_OUT_OF_RESOURCE;
  63     }
  64     array->array_size = size;
  65     return PMIX_SUCCESS;
  66 }

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