2006-06-08 08:29:27 +04:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
|
|
|
|
* University Research and Technology
|
|
|
|
* Corporation. All rights reserved.
|
|
|
|
* Copyright (c) 2004-2005 The University of Tennessee and The University
|
|
|
|
* of Tennessee Research Foundation. 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.5A
|
|
|
|
* $COPYRIGHT$
|
|
|
|
*
|
|
|
|
* Additional copyrights may follow
|
|
|
|
*
|
|
|
|
* $HEADER$
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* Description of the Registration Cache framework
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "opal/mca/mca.h"
|
|
|
|
#include "mpool_base_tree.h"
|
|
|
|
|
|
|
|
|
2006-06-12 20:44:00 +04:00
|
|
|
OBJ_CLASS_INSTANCE(mca_mpool_base_tree_item_t, ompi_free_list_item_t, NULL, NULL);
|
2006-06-08 08:29:27 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* use globals for the tree and the tree_item free list..
|
|
|
|
*/
|
|
|
|
ompi_rb_tree_t mca_mpool_base_tree;
|
|
|
|
ompi_free_list_t mca_mpool_base_tree_item_free_list;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* simple minded compare function...
|
|
|
|
*/
|
|
|
|
int mca_mpool_base_tree_node_compare(void * key1, void * key2)
|
|
|
|
{
|
|
|
|
if(key1 < key2)
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
else if(key1 > key2)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* initialize the rb tree
|
|
|
|
*/
|
|
|
|
int mca_mpool_base_tree_init(void) {
|
|
|
|
int rc;
|
|
|
|
OBJ_CONSTRUCT(&mca_mpool_base_tree, ompi_rb_tree_t);
|
|
|
|
OBJ_CONSTRUCT(&mca_mpool_base_tree_item_free_list, ompi_free_list_t);
|
|
|
|
rc = ompi_free_list_init(&mca_mpool_base_tree_item_free_list, sizeof(mca_mpool_base_tree_item_t),
|
|
|
|
OBJ_CLASS(mca_mpool_base_tree_item_t), 0, -1 , 4, NULL);
|
|
|
|
if(OMPI_SUCCESS == rc) {
|
|
|
|
rc = ompi_rb_tree_init(&mca_mpool_base_tree, mca_mpool_base_tree_node_compare);
|
|
|
|
}
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* insert an item in the rb tree
|
|
|
|
*/
|
|
|
|
int mca_mpool_base_tree_insert(mca_mpool_base_tree_item_t* item) {
|
|
|
|
return ompi_rb_tree_insert(&mca_mpool_base_tree, item->key, item);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* remove an item from the rb tree
|
|
|
|
*/
|
|
|
|
int mca_mpool_base_tree_delete(mca_mpool_base_tree_item_t* item) {
|
|
|
|
int rc;
|
|
|
|
rc = ompi_rb_tree_delete(&mca_mpool_base_tree, item->key);
|
|
|
|
if(OMPI_SUCCESS == rc) {
|
2006-06-08 18:23:20 +04:00
|
|
|
mca_mpool_base_tree_item_put(item);
|
2006-06-08 08:29:27 +04:00
|
|
|
}
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* find the item in the rb tree
|
|
|
|
*/
|
|
|
|
mca_mpool_base_tree_item_t* mca_mpool_base_tree_find(void* base) {
|
|
|
|
return(ompi_rb_tree_find(&mca_mpool_base_tree, base));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* get a tree item from the free list
|
|
|
|
*/
|
|
|
|
mca_mpool_base_tree_item_t* mca_mpool_base_tree_item_get(void) {
|
2006-06-12 20:44:00 +04:00
|
|
|
ompi_free_list_item_t* item = NULL;
|
2006-06-08 08:29:27 +04:00
|
|
|
int rc;
|
|
|
|
OMPI_FREE_LIST_GET(&mca_mpool_base_tree_item_free_list,
|
|
|
|
item,
|
|
|
|
rc);
|
|
|
|
if(OMPI_SUCCESS == rc) {
|
|
|
|
return (mca_mpool_base_tree_item_t*) item;
|
|
|
|
} else {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
2006-06-08 18:23:20 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* put an item back into the free list
|
|
|
|
*/
|
|
|
|
void mca_mpool_base_tree_item_put(mca_mpool_base_tree_item_t* item) {
|
|
|
|
OMPI_FREE_LIST_RETURN(&mca_mpool_base_tree_item_free_list,
|
2006-06-12 00:19:12 +04:00
|
|
|
&(item->super));
|
2006-06-08 18:23:20 +04:00
|
|
|
}
|