2004-02-09 23:03:03 +03: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.
|
|
|
|
* $COPYRIGHT$
|
|
|
|
*
|
|
|
|
* Additional copyrights may follow
|
|
|
|
*
|
2004-02-09 23:03:03 +03:00
|
|
|
* $HEADER$
|
|
|
|
*/
|
2004-10-23 23:24:00 +04:00
|
|
|
/** @file
|
|
|
|
*
|
|
|
|
* 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"
|
|
|
|
|
2004-03-17 21:45:16 +03:00
|
|
|
#include "threads/mutex.h"
|
2004-06-07 19:33:53 +04:00
|
|
|
#include "class/ompi_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 */
|
2004-06-07 19:33:53 +04:00
|
|
|
ompi_object_t super;
|
2004-10-23 23:24:00 +04:00
|
|
|
/** synchronization object */
|
2004-06-07 19:33:53 +04:00
|
|
|
ompi_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;
|
|
|
|
/** number of fee elements in the list */
|
|
|
|
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-09 23:03:03 +03:00
|
|
|
|
2004-02-10 23:54:15 +03:00
|
|
|
|
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
|
|
|
|
*
|
|
|
|
* @param array Pointer to array (IN)
|
|
|
|
* @param index Index of element to be returned (IN)
|
|
|
|
*
|
|
|
|
* @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,
|
|
|
|
int index)
|
2004-05-19 01:06:11 +04:00
|
|
|
{
|
|
|
|
void *p;
|
2004-06-25 01:39:08 +04:00
|
|
|
OMPI_THREAD_LOCK(&(table->lock));
|
2004-05-19 01:06:11 +04:00
|
|
|
p = table->addr[index];
|
2004-06-25 01:39:08 +04:00
|
|
|
OMPI_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);
|
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 */
|