2004-06-15 23:46:26 +04:00
|
|
|
/*
|
2004-11-22 04:38:40 +03:00
|
|
|
* 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.
|
2004-11-28 23:09:25 +03:00
|
|
|
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
|
|
|
|
* University of Stuttgart. All rights reserved.
|
2005-03-24 15:43:37 +03:00
|
|
|
* Copyright (c) 2004-2005 The Regents of the University of California.
|
|
|
|
* All rights reserved.
|
2004-11-22 04:38:40 +03:00
|
|
|
* $COPYRIGHT$
|
|
|
|
*
|
|
|
|
* Additional copyrights may follow
|
|
|
|
*
|
2004-06-15 23:46:26 +04:00
|
|
|
* $HEADER$
|
|
|
|
*/
|
2004-08-19 03:24:27 +04:00
|
|
|
|
2004-06-15 23:46:26 +04:00
|
|
|
#include "ompi_config.h"
|
2004-08-19 03:24:27 +04:00
|
|
|
|
2005-07-02 20:46:27 +04:00
|
|
|
#include "opal/class/opal_free_list.h"
|
|
|
|
#include "opal/include/sys/cache.h"
|
2004-06-15 23:46:26 +04:00
|
|
|
|
|
|
|
|
2005-07-02 19:42:29 +04:00
|
|
|
static void opal_free_list_construct(opal_free_list_t* fl);
|
|
|
|
static void opal_free_list_destruct(opal_free_list_t* fl);
|
2004-06-15 23:46:26 +04:00
|
|
|
|
|
|
|
|
2005-07-03 20:06:07 +04:00
|
|
|
opal_class_t opal_free_list_t_class = {
|
2005-07-02 19:42:29 +04:00
|
|
|
"opal_free_list_t",
|
2005-07-03 20:22:16 +04:00
|
|
|
OBJ_CLASS(opal_list_t),
|
2005-07-03 20:06:07 +04:00
|
|
|
(opal_construct_t)opal_free_list_construct,
|
|
|
|
(opal_destruct_t)opal_free_list_destruct
|
2004-06-15 23:46:26 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2005-07-02 19:42:29 +04:00
|
|
|
static void opal_free_list_construct(opal_free_list_t* fl)
|
2004-06-15 23:46:26 +04:00
|
|
|
{
|
2005-07-04 02:45:48 +04:00
|
|
|
OBJ_CONSTRUCT(&fl->fl_lock, opal_mutex_t);
|
2005-09-02 20:00:42 +04:00
|
|
|
OBJ_CONSTRUCT(&fl->fl_condition, opal_condition_t);
|
2004-06-15 23:46:26 +04:00
|
|
|
fl->fl_max_to_alloc = 0;
|
|
|
|
fl->fl_num_allocated = 0;
|
|
|
|
fl->fl_num_per_alloc = 0;
|
2004-10-19 20:56:45 +04:00
|
|
|
fl->fl_num_waiting = 0;
|
2004-06-15 23:46:26 +04:00
|
|
|
fl->fl_elem_size = 0;
|
|
|
|
fl->fl_elem_class = 0;
|
|
|
|
}
|
|
|
|
|
2005-07-02 19:42:29 +04:00
|
|
|
static void opal_free_list_destruct(opal_free_list_t* fl)
|
2004-06-15 23:46:26 +04:00
|
|
|
{
|
2005-09-02 20:00:42 +04:00
|
|
|
OBJ_DESTRUCT(&fl->fl_condition);
|
2004-06-15 23:46:26 +04:00
|
|
|
OBJ_DESTRUCT(&fl->fl_lock);
|
|
|
|
}
|
|
|
|
|
2005-07-02 19:42:29 +04:00
|
|
|
int opal_free_list_init(
|
|
|
|
opal_free_list_t *flist,
|
2004-06-15 23:46:26 +04:00
|
|
|
size_t elem_size,
|
2005-07-03 20:06:07 +04:00
|
|
|
opal_class_t* elem_class,
|
2004-06-15 23:46:26 +04:00
|
|
|
int num_elements_to_alloc,
|
|
|
|
int max_elements_to_alloc,
|
2005-07-02 19:42:29 +04:00
|
|
|
int num_elements_per_alloc)
|
2004-06-15 23:46:26 +04:00
|
|
|
{
|
|
|
|
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;
|
2004-07-15 22:08:20 +04:00
|
|
|
if(num_elements_to_alloc)
|
2005-07-02 19:42:29 +04:00
|
|
|
return opal_free_list_grow(flist, num_elements_to_alloc);
|
2004-07-15 22:08:20 +04:00
|
|
|
return OMPI_SUCCESS;
|
2004-06-15 23:46:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-07-02 19:42:29 +04:00
|
|
|
int opal_free_list_grow(opal_free_list_t* flist, size_t num_elements)
|
2004-06-15 23:46:26 +04:00
|
|
|
{
|
|
|
|
unsigned char* ptr;
|
|
|
|
size_t i;
|
2005-05-24 02:06:50 +04:00
|
|
|
size_t mod;
|
|
|
|
|
2004-06-15 23:46:26 +04:00
|
|
|
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;
|
|
|
|
|
2005-07-02 19:42:29 +04:00
|
|
|
ptr = (unsigned char *)malloc((num_elements * flist->fl_elem_size) + CACHE_LINE_SIZE);
|
2004-06-15 23:46:26 +04:00
|
|
|
if(NULL == ptr)
|
|
|
|
return OMPI_ERR_TEMP_OUT_OF_RESOURCE;
|
|
|
|
|
2005-05-24 02:06:50 +04:00
|
|
|
mod = (unsigned long)ptr % CACHE_LINE_SIZE;
|
|
|
|
if(mod != 0) {
|
|
|
|
ptr += (CACHE_LINE_SIZE - mod);
|
|
|
|
}
|
|
|
|
|
2004-06-15 23:46:26 +04:00
|
|
|
for(i=0; i<num_elements; i++) {
|
2005-07-02 19:42:29 +04:00
|
|
|
opal_free_list_item_t* item = (opal_free_list_item_t*)ptr;
|
|
|
|
item->user_data = NULL;
|
2004-06-15 23:46:26 +04:00
|
|
|
if (NULL != flist->fl_elem_class) {
|
|
|
|
OBJ_CONSTRUCT_INTERNAL(item, flist->fl_elem_class);
|
|
|
|
}
|
2005-07-03 20:22:16 +04:00
|
|
|
opal_list_append(&(flist->super), &(item->super));
|
2004-06-15 23:46:26 +04:00
|
|
|
ptr += flist->fl_elem_size;
|
|
|
|
}
|
|
|
|
flist->fl_num_allocated += num_elements;
|
|
|
|
return OMPI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|