2004-02-09 23:03:03 +03:00
|
|
|
/*
|
2005-11-05 22:57:48 +03:00
|
|
|
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
|
|
|
|
* University Research and Technology
|
|
|
|
* Corporation. All rights reserved.
|
2006-08-24 20:38:08 +04:00
|
|
|
* Copyright (c) 2004-2006 The University of Tennessee and The University
|
2005-11-05 22:57:48 +03:00
|
|
|
* of Tennessee Research Foundation. 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-02-09 23:03:03 +03:00
|
|
|
* $HEADER$
|
|
|
|
*/
|
2004-10-23 23:24:00 +04:00
|
|
|
/** @file
|
2005-05-26 17:12:11 +04:00
|
|
|
*
|
|
|
|
* See ompi_bitmap.h for an explanation of why there is a split
|
|
|
|
* between OMPI and ORTE for this generic class.
|
2004-10-23 23:24:00 +04:00
|
|
|
*
|
|
|
|
* Utility functions to manage fortran <-> c opaque object
|
|
|
|
* translation. Note that since MPI defines fortran handles as
|
|
|
|
* [signed] int's, we use int everywhere in here where you would
|
|
|
|
* normally expect size_t. There's some code that makes sure indices
|
|
|
|
* don't go above FORTRAN_HANDLE_MAX (which is min(INT_MAX, fortran
|
|
|
|
* INTEGER max)), just to be sure.
|
|
|
|
*/
|
2004-02-09 23:03:03 +03:00
|
|
|
|
2004-06-07 19:33:53 +04:00
|
|
|
#ifndef OMPI_POINTER_ARRAY_H
|
|
|
|
#define OMPI_POINTER_ARRAY_H
|
2004-02-09 23:03:03 +03:00
|
|
|
|
2004-10-23 23:24:00 +04:00
|
|
|
#include "ompi_config.h"
|
|
|
|
|
2005-07-04 02:45:48 +04:00
|
|
|
#include "opal/threads/mutex.h"
|
2005-07-03 20:06:07 +04:00
|
|
|
#include "opal/class/opal_object.h"
|
2004-02-09 23:03:03 +03:00
|
|
|
|
2004-10-21 02:31:03 +04:00
|
|
|
#if defined(c_plusplus) || defined(__cplusplus)
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
2004-02-09 23:03:03 +03:00
|
|
|
|
2004-10-23 23:24:00 +04:00
|
|
|
/**
|
2004-02-10 02:27:43 +03:00
|
|
|
* dynamic pointer array
|
2004-02-09 23:03:03 +03:00
|
|
|
*/
|
2004-06-07 19:33:53 +04:00
|
|
|
struct ompi_pointer_array_t {
|
2004-10-23 23:24:00 +04:00
|
|
|
/** base class */
|
2005-07-03 20:06:07 +04:00
|
|
|
opal_object_t super;
|
2004-10-23 23:24:00 +04:00
|
|
|
/** synchronization object */
|
2005-07-04 02:45:48 +04:00
|
|
|
opal_mutex_t lock;
|
2004-10-23 23:24:00 +04:00
|
|
|
/** Index of lowest free element. NOTE: This is only an
|
|
|
|
optimization to know where to search for the first free slot.
|
|
|
|
It does \em not necessarily imply indices all above this index
|
|
|
|
are not taken! */
|
|
|
|
int lowest_free;
|
2006-09-18 21:57:55 +04:00
|
|
|
/** number of free elements in the list */
|
2004-10-23 23:24:00 +04:00
|
|
|
int number_free;
|
|
|
|
/** size of list, i.e. number of elements in addr */
|
|
|
|
int size;
|
|
|
|
/** pointer to array of pointers */
|
2004-02-09 23:03:03 +03:00
|
|
|
void **addr;
|
|
|
|
};
|
2004-10-23 23:24:00 +04:00
|
|
|
/**
|
|
|
|
* Convenience typedef
|
|
|
|
*/
|
|
|
|
typedef struct ompi_pointer_array_t ompi_pointer_array_t;
|
|
|
|
/**
|
|
|
|
* Class declaration
|
|
|
|
*/
|
|
|
|
OMPI_DECLSPEC OBJ_CLASS_DECLARATION(ompi_pointer_array_t);
|
|
|
|
|
2004-02-10 02:27:43 +03:00
|
|
|
/**
|
|
|
|
* Add a pointer to the array (Grow the array, if need be)
|
|
|
|
*
|
|
|
|
* @param array Pointer to array (IN)
|
|
|
|
* @param ptr Pointer value (IN)
|
|
|
|
*
|
|
|
|
* @return Index of inserted array element. Return value of
|
2004-10-23 23:24:00 +04:00
|
|
|
* (-1) indicates an error.
|
2004-02-10 02:27:43 +03:00
|
|
|
*/
|
2004-10-28 22:13:43 +04:00
|
|
|
OMPI_DECLSPEC int ompi_pointer_array_add(ompi_pointer_array_t *array, void *ptr);
|
2004-02-10 02:27:43 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the value of an element in array
|
|
|
|
*
|
|
|
|
* @param array Pointer to array (IN)
|
|
|
|
* @param index Index of element to be reset (IN)
|
|
|
|
* @param value New value to be set at element index (IN)
|
|
|
|
*
|
|
|
|
* @return Error code. (-1) indicates an error.
|
|
|
|
*/
|
2004-10-28 22:13:43 +04:00
|
|
|
OMPI_DECLSPEC int ompi_pointer_array_set_item(ompi_pointer_array_t *array,
|
2004-10-23 23:24:00 +04:00
|
|
|
int index, void *value);
|
2004-02-10 02:27:43 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the value of an element in array
|
|
|
|
*
|
2007-01-19 22:48:06 +03:00
|
|
|
* @param array Pointer to array (IN)
|
|
|
|
* @param element_index Index of element to be returned (IN)
|
2004-02-10 02:27:43 +03:00
|
|
|
*
|
|
|
|
* @return Error code. NULL indicates an error.
|
|
|
|
*/
|
2004-05-19 01:06:11 +04:00
|
|
|
|
2004-10-23 23:24:00 +04:00
|
|
|
static inline void *ompi_pointer_array_get_item(ompi_pointer_array_t *table,
|
2007-01-19 22:48:06 +03:00
|
|
|
int element_index)
|
2004-05-19 01:06:11 +04:00
|
|
|
{
|
|
|
|
void *p;
|
2006-08-24 20:38:08 +04:00
|
|
|
|
2007-01-19 22:48:06 +03:00
|
|
|
if( table->size <= element_index ) {
|
2006-08-24 20:38:08 +04:00
|
|
|
return NULL;
|
|
|
|
}
|
2005-07-04 02:45:48 +04:00
|
|
|
OPAL_THREAD_LOCK(&(table->lock));
|
2007-01-19 22:48:06 +03:00
|
|
|
p = table->addr[element_index];
|
2005-07-04 02:45:48 +04:00
|
|
|
OPAL_THREAD_UNLOCK(&(table->lock));
|
2004-05-19 01:06:11 +04:00
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2004-02-09 23:03:03 +03:00
|
|
|
|
2004-03-20 04:54:18 +03:00
|
|
|
/**
|
|
|
|
* Get the size of the pointer array
|
|
|
|
*
|
|
|
|
* @param array Pointer to array (IN)
|
|
|
|
*
|
|
|
|
* @returns size Size of the array
|
|
|
|
*
|
|
|
|
* Simple inline function to return the size of the array in order to
|
|
|
|
* hide the member field from external users.
|
|
|
|
*/
|
2004-10-23 23:24:00 +04:00
|
|
|
static inline int ompi_pointer_array_get_size(ompi_pointer_array_t *array)
|
2004-03-20 04:54:18 +03:00
|
|
|
{
|
|
|
|
return array->size;
|
|
|
|
}
|
|
|
|
|
2004-10-23 23:24:00 +04:00
|
|
|
|
2004-05-21 01:13:11 +04:00
|
|
|
/**
|
|
|
|
* Test whether a certain element is already in use. If not yet
|
|
|
|
* in use, reserve it.
|
|
|
|
*
|
|
|
|
* @param array Pointer to array (IN)
|
|
|
|
* @param index Index of element to be tested (IN)
|
|
|
|
* @param value New value to be set at element index (IN)
|
|
|
|
*
|
|
|
|
* @return true/false True if element could be reserved
|
2004-10-23 23:24:00 +04:00
|
|
|
* False if element could not be reserved (e.g., in use).
|
2004-05-21 01:13:11 +04:00
|
|
|
*
|
|
|
|
* In contrary to array_set, this function does not allow to overwrite
|
|
|
|
* a value, unless the previous value is NULL ( equiv. to free ).
|
|
|
|
*/
|
2004-10-28 22:13:43 +04:00
|
|
|
OMPI_DECLSPEC bool ompi_pointer_array_test_and_set_item (ompi_pointer_array_t *table,
|
2004-10-23 23:24:00 +04:00
|
|
|
int index,
|
|
|
|
void *value);
|
2005-10-04 03:29:26 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Empty the array.
|
|
|
|
*
|
|
|
|
* @param array Pointer to array (IN)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static inline void ompi_pointer_array_remove_all(ompi_pointer_array_t *array)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
OPAL_THREAD_LOCK(&array->lock);
|
|
|
|
array->lowest_free = 0;
|
|
|
|
array->number_free = array->size;
|
|
|
|
for(i=0; i<array->size; i++) {
|
|
|
|
array->addr[i] = NULL;
|
|
|
|
}
|
|
|
|
OPAL_THREAD_UNLOCK(&array->lock);
|
|
|
|
}
|
|
|
|
|
2004-10-21 02:31:03 +04:00
|
|
|
#if defined(c_plusplus) || defined(__cplusplus)
|
|
|
|
}
|
|
|
|
#endif
|
2004-06-07 19:33:53 +04:00
|
|
|
#endif /* OMPI_POINTER_ARRAY_H */
|