1
1
openmpi/ompi/class/ompi_free_list.c

110 строки
3.1 KiB
C
Исходник Обычный вид История

/*
* Copyright (c) 2004-2005 The Trustees of Indiana University.
* All rights reserved.
* Copyright (c) 2004-2005 The Trustees of the University of Tennessee.
* All rights reserved.
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
* University of Stuttgart. All rights reserved.
* Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#include "ompi_config.h"
#include "class/ompi_free_list.h"
#include "include/sys/cache.h"
static void ompi_free_list_construct(ompi_free_list_t* fl);
static void ompi_free_list_destruct(ompi_free_list_t* fl);
opal_class_t ompi_free_list_t_class = {
"ompi_free_list_t",
OBJ_CLASS(opal_list_t),
(opal_construct_t)ompi_free_list_construct,
(opal_destruct_t)ompi_free_list_destruct
};
static void ompi_free_list_construct(ompi_free_list_t* fl)
{
OBJ_CONSTRUCT(&fl->fl_lock, opal_mutex_t);
fl->fl_max_to_alloc = 0;
fl->fl_num_allocated = 0;
fl->fl_num_per_alloc = 0;
fl->fl_num_waiting = 0;
fl->fl_elem_size = 0;
fl->fl_elem_class = 0;
fl->fl_mpool = 0;
}
static void ompi_free_list_destruct(ompi_free_list_t* fl)
{
OBJ_DESTRUCT(&fl->fl_lock);
}
int ompi_free_list_init(
ompi_free_list_t *flist,
size_t elem_size,
opal_class_t* elem_class,
int num_elements_to_alloc,
int max_elements_to_alloc,
int num_elements_per_alloc,
- massive change for module<-->component name fixes throughout the code base. - many (most) mca type names have "component" or "module" in them, as relevant, just to further distinguish the difference between component data/actions and module data/actions. All developers are encouraged to perpetuate this convention when you create types that are specific to a framework, component, or module - did very little to entire framework (just the basics to make it compile) because it's just about to be almost entirely replaced - ditto for io / romio - did not work on elan or ib components; have to commit and then convert those on a different machine with the right libraries and headers - renamed a bunch of *_module.c files to *_component.c and *module*c to *component*c (a few still remain, e.g., ptl/ib, ptl/elan, etc.) - modified autogen/configure/build process to match new filenames (e.g., output static-components.h instead of static-modules.h) - removed DOS-style cr/lf stuff in ns/ns.h - added newline to end of file src/util/numtostr.h - removed some redundant error checking in the top-level topo functions - added a few {} here and there where people "forgot" to put them in for 1 line blocks ;-) - removed a bunch of MPI_* types from mca header files (replaced with corresponding ompi_* types) - all the ptl components had version numbers in their structs; removed - converted a few more elements in the MCA base to use the OBJ interface -- removed some old manual reference counting kruft This commit was SVN r1830.
2004-08-02 04:24:22 +04:00
mca_mpool_base_module_t* mpool)
{
flist->fl_elem_size = elem_size;
flist->fl_elem_class = elem_class;
flist->fl_max_to_alloc = max_elements_to_alloc;
flist->fl_num_allocated = 0;
flist->fl_num_per_alloc = num_elements_per_alloc;
flist->fl_mpool = mpool;
if(num_elements_to_alloc)
return ompi_free_list_grow(flist, num_elements_to_alloc);
return OMPI_SUCCESS;
}
int ompi_free_list_grow(ompi_free_list_t* flist, size_t num_elements)
{
unsigned char* ptr;
size_t i;
size_t mod;
mca_mpool_base_registration_t* user_out;
if (flist->fl_max_to_alloc > 0 && flist->fl_num_allocated + num_elements > flist->fl_max_to_alloc)
return OMPI_ERR_TEMP_OUT_OF_RESOURCE;
if (NULL != flist->fl_mpool)
ptr = (unsigned char*)flist->fl_mpool->mpool_alloc(flist->fl_mpool, (num_elements * flist->fl_elem_size) + CACHE_LINE_SIZE, 0, &user_out);
else
ptr = (unsigned char *)malloc((num_elements * flist->fl_elem_size) + CACHE_LINE_SIZE);
if(NULL == ptr)
return OMPI_ERR_TEMP_OUT_OF_RESOURCE;
mod = (unsigned long)ptr % CACHE_LINE_SIZE;
if(mod != 0) {
ptr += (CACHE_LINE_SIZE - mod);
}
for(i=0; i<num_elements; i++) {
ompi_free_list_item_t* item = (ompi_free_list_item_t*)ptr;
item->user_data = user_out;
if (NULL != flist->fl_elem_class) {
OBJ_CONSTRUCT_INTERNAL(item, flist->fl_elem_class);
}
opal_list_append(&(flist->super), &(item->super));
ptr += flist->fl_elem_size;
}
flist->fl_num_allocated += num_elements;
return OMPI_SUCCESS;
}