2003-12-22 19:29:21 +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-07-13 08:56:15 +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.
|
2007-09-11 19:40:30 +04:00
|
|
|
* Copyright (c) 2007 Voltaire All rights reserved.
|
2004-11-22 04:38:40 +03:00
|
|
|
* $COPYRIGHT$
|
|
|
|
*
|
|
|
|
* Additional copyrights may follow
|
|
|
|
*
|
2004-01-07 21:39:35 +03:00
|
|
|
* $HEADER$
|
2003-12-22 19:29:21 +03:00
|
|
|
*/
|
2004-08-11 20:18:52 +04:00
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
*
|
2005-07-03 20:22:16 +04:00
|
|
|
* The opal_list_t interface is used to provide a generic
|
2004-08-11 20:18:52 +04:00
|
|
|
* doubly-linked list container for Open MPI. It was inspired by (but
|
|
|
|
* is slightly different than) the Stantard Template Library (STL)
|
|
|
|
* std::list class. One notable difference from std::list is that
|
2005-07-03 20:22:16 +04:00
|
|
|
* when an opal_list_t is destroyed, all of the opal_list_item_t
|
2004-08-11 20:18:52 +04:00
|
|
|
* objects that it contains are orphaned -- they are \em not
|
|
|
|
* destroyed.
|
|
|
|
*
|
2005-07-03 20:22:16 +04:00
|
|
|
* The general idea is that opal_list_item_t objects can be put on an
|
|
|
|
* opal_list_t. Hence, you create a new type that derives from
|
|
|
|
* opal_list_item_t; this new type can then be used with opal_list_t
|
2004-08-11 20:18:52 +04:00
|
|
|
* containers.
|
|
|
|
*
|
2005-07-03 20:22:16 +04:00
|
|
|
* NOTE: opal_list_item_t instances can only be on \em one list at a
|
|
|
|
* time. Specifically, if you add an opal_list_item_t to one list,
|
2004-08-11 20:18:52 +04:00
|
|
|
* and then add it to another list (without first removing it from the
|
|
|
|
* first list), you will effectively be hosing the first list. You
|
|
|
|
* have been warned.
|
2005-04-08 19:31:28 +04:00
|
|
|
*
|
|
|
|
* If OMPI_ENABLE_DEBUG is true, a bunch of checks occur, including
|
|
|
|
* some spot checks for a debugging reference count in an attempt to
|
2005-07-03 20:22:16 +04:00
|
|
|
* ensure that an opal_list_item_t is only one *one* list at a time.
|
2005-04-08 19:31:28 +04:00
|
|
|
* Given the highly concurrent nature of this class, these spot checks
|
|
|
|
* cannot guarantee that an item is only one list at a time.
|
|
|
|
* Specifically, since it is a desirable attribute of this class to
|
|
|
|
* not use locks for normal operations, it is possible that two
|
2005-07-03 20:22:16 +04:00
|
|
|
* threads may [erroneously] modify an opal_list_item_t concurrently.
|
2005-04-08 19:31:28 +04:00
|
|
|
*
|
|
|
|
* The only way to guarantee that a debugging reference count is valid
|
|
|
|
* for the duration of an operation is to lock the item_t during the
|
|
|
|
* operation. But this fundamentally changes the desirable attribute
|
|
|
|
* of this class (i.e., no locks). So all we can do is spot-check the
|
|
|
|
* reference count in a bunch of places and check that it is still the
|
|
|
|
* value that we think it should be. But this doesn't mean that you
|
|
|
|
* can run into "unlucky" cases where two threads are concurrently
|
|
|
|
* modifying an item_t, but all the spot checks still return the
|
|
|
|
* "right" values. All we can do is hope that we have enough spot
|
|
|
|
* checks to statistically drive down the possibility of the unlucky
|
|
|
|
* cases happening.
|
2004-08-11 20:18:52 +04:00
|
|
|
*/
|
2003-12-22 19:29:21 +03:00
|
|
|
|
2005-07-03 20:22:16 +04:00
|
|
|
#ifndef OPAL_LIST_H
|
|
|
|
#define OPAL_LIST_H
|
2003-12-22 19:29:21 +03:00
|
|
|
|
2004-01-14 02:26:14 +03:00
|
|
|
#include <stdio.h>
|
2004-08-17 23:31:07 +04:00
|
|
|
#include <stdlib.h>
|
2005-07-03 20:06:07 +04:00
|
|
|
#include "opal/class/opal_object.h"
|
2003-12-22 19:29:21 +03:00
|
|
|
|
2005-04-08 19:31:28 +04:00
|
|
|
#if OMPI_ENABLE_DEBUG
|
|
|
|
/* Need atomics for debugging (reference counting) */
|
2006-02-12 04:33:29 +03:00
|
|
|
#include "opal/sys/atomic.h"
|
2005-07-04 02:45:48 +04:00
|
|
|
#include "opal/threads/mutex.h"
|
2005-04-08 19:31:28 +04:00
|
|
|
#endif
|
|
|
|
|
2004-10-21 02:31:03 +04:00
|
|
|
#if defined(c_plusplus) || defined(__cplusplus)
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
2004-08-11 20:18:52 +04:00
|
|
|
/**
|
|
|
|
* \internal
|
2003-12-22 19:29:21 +03:00
|
|
|
*
|
2004-08-11 20:18:52 +04:00
|
|
|
* The class for the list container.
|
|
|
|
*/
|
2006-08-20 19:54:04 +04:00
|
|
|
OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_list_t);
|
2004-08-11 20:18:52 +04:00
|
|
|
/**
|
|
|
|
* \internal
|
2003-12-22 19:29:21 +03:00
|
|
|
*
|
2005-07-03 20:22:16 +04:00
|
|
|
* Base class for items that are put in list (opal_list_t) containers.
|
2003-12-22 19:29:21 +03:00
|
|
|
*/
|
2006-08-20 19:54:04 +04:00
|
|
|
OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_list_item_t);
|
2003-12-22 19:29:21 +03:00
|
|
|
|
|
|
|
|
2004-08-11 20:18:52 +04:00
|
|
|
/**
|
|
|
|
* \internal
|
|
|
|
*
|
2005-07-03 20:22:16 +04:00
|
|
|
* Struct of an opal_list_item_t
|
2003-12-22 19:29:21 +03:00
|
|
|
*/
|
2005-07-03 20:22:16 +04:00
|
|
|
struct opal_list_item_t
|
2003-12-22 19:29:21 +03:00
|
|
|
{
|
2005-07-03 20:06:07 +04:00
|
|
|
opal_object_t super;
|
2004-08-11 20:18:52 +04:00
|
|
|
/**< Generic parent class for all Open MPI objects */
|
2005-07-03 20:22:16 +04:00
|
|
|
volatile struct opal_list_item_t *opal_list_next;
|
2004-08-11 20:18:52 +04:00
|
|
|
/**< Pointer to next list item */
|
2005-07-03 20:22:16 +04:00
|
|
|
volatile struct opal_list_item_t *opal_list_prev;
|
2004-08-11 20:18:52 +04:00
|
|
|
/**< Pointer to previous list item */
|
2007-09-11 19:40:30 +04:00
|
|
|
int32_t item_free;
|
2005-04-08 19:31:28 +04:00
|
|
|
|
|
|
|
#if OMPI_ENABLE_DEBUG
|
2005-04-13 09:14:21 +04:00
|
|
|
/** Atomic reference count for debugging */
|
2005-07-03 20:22:16 +04:00
|
|
|
volatile int32_t opal_list_item_refcount;
|
2005-04-13 09:14:21 +04:00
|
|
|
/** The list this item belong to */
|
2005-07-03 20:22:16 +04:00
|
|
|
volatile struct opal_list_t* opal_list_item_belong_to;
|
2005-04-08 19:31:28 +04:00
|
|
|
#endif
|
2004-08-11 20:18:52 +04:00
|
|
|
};
|
|
|
|
/**
|
2005-07-03 20:22:16 +04:00
|
|
|
* Base type for items that are put in a list (opal_list_t) containers.
|
2004-08-11 20:18:52 +04:00
|
|
|
*/
|
2005-07-03 20:22:16 +04:00
|
|
|
typedef struct opal_list_item_t opal_list_item_t;
|
2003-12-22 19:29:21 +03:00
|
|
|
|
|
|
|
|
2004-08-11 20:18:52 +04:00
|
|
|
/**
|
|
|
|
* Get the next item in a list.
|
|
|
|
*
|
|
|
|
* @param item A list item.
|
|
|
|
*
|
|
|
|
* @returns The next item in the list
|
|
|
|
*/
|
2005-07-03 20:22:16 +04:00
|
|
|
#define opal_list_get_next(item) \
|
|
|
|
((item) ? ((opal_list_item_t*) ((opal_list_item_t*)(item))->opal_list_next) : NULL)
|
2003-12-22 19:29:21 +03:00
|
|
|
|
2004-08-11 20:18:52 +04:00
|
|
|
/**
|
|
|
|
* Get the next item in a list.
|
|
|
|
*
|
|
|
|
* @param item A list item.
|
|
|
|
*
|
|
|
|
* @returns The next item in the list
|
|
|
|
*/
|
2005-07-03 20:22:16 +04:00
|
|
|
#define opal_list_get_prev(item) \
|
|
|
|
((item) ? ((opal_list_item_t*) ((opal_list_item_t*)(item))->opal_list_prev) : NULL)
|
2003-12-22 19:29:21 +03:00
|
|
|
|
2004-08-11 20:18:52 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \internal
|
2003-12-22 19:29:21 +03:00
|
|
|
*
|
2005-07-03 20:22:16 +04:00
|
|
|
* Struct of an opal_list_t
|
2003-12-22 19:29:21 +03:00
|
|
|
*/
|
2005-07-03 20:22:16 +04:00
|
|
|
struct opal_list_t
|
2003-12-22 19:29:21 +03:00
|
|
|
{
|
2005-07-03 20:06:07 +04:00
|
|
|
opal_object_t super;
|
2004-08-11 20:18:52 +04:00
|
|
|
/**< Generic parent class for all Open MPI objects */
|
2006-07-13 08:56:15 +04:00
|
|
|
opal_list_item_t opal_list_sentinel;
|
|
|
|
/**< Head and tail item of the list */
|
2005-07-03 20:22:16 +04:00
|
|
|
volatile size_t opal_list_length;
|
2004-08-11 20:18:52 +04:00
|
|
|
/**< Quick reference to the number of items in the list */
|
|
|
|
};
|
|
|
|
/**
|
|
|
|
* List container type.
|
|
|
|
*/
|
2005-07-03 20:22:16 +04:00
|
|
|
typedef struct opal_list_t opal_list_t;
|
2003-12-22 19:29:21 +03:00
|
|
|
|
|
|
|
|
2004-08-11 20:18:52 +04:00
|
|
|
/**
|
2004-08-17 23:31:07 +04:00
|
|
|
* Check for empty list
|
2004-08-11 20:18:52 +04:00
|
|
|
*
|
|
|
|
* @param list The list container
|
|
|
|
*
|
2004-08-17 23:31:07 +04:00
|
|
|
* @returns true if list's size is 0, false otherwise
|
2004-08-11 20:18:52 +04:00
|
|
|
*
|
2004-08-17 23:31:07 +04:00
|
|
|
* This is an O(1) operation.
|
2004-08-11 20:18:52 +04:00
|
|
|
*
|
2004-08-17 23:31:07 +04:00
|
|
|
* This is an inlined function in compilers that support inlining,
|
|
|
|
* so it's usually a cheap operation.
|
2003-12-22 19:29:21 +03:00
|
|
|
*/
|
2005-07-03 20:22:16 +04:00
|
|
|
static inline bool opal_list_is_empty(opal_list_t* list)
|
2004-01-13 03:36:37 +03:00
|
|
|
{
|
2006-07-13 08:56:15 +04:00
|
|
|
return (list->opal_list_sentinel.opal_list_next ==
|
2006-08-23 04:29:35 +04:00
|
|
|
&(list->opal_list_sentinel) ? true : false);
|
2004-01-13 03:36:37 +03:00
|
|
|
}
|
2003-12-22 19:29:21 +03:00
|
|
|
|
2004-08-17 23:31:07 +04:00
|
|
|
|
2004-08-11 20:18:52 +04:00
|
|
|
/**
|
|
|
|
* Return the first item on the list (does not remove it).
|
|
|
|
*
|
|
|
|
* @param list The list container
|
|
|
|
*
|
|
|
|
* @returns A pointer to the first item on the list
|
|
|
|
*
|
|
|
|
* This is an O(1) operation to return the first item on the list. It
|
|
|
|
* should be compared against the returned value from
|
2005-07-03 20:22:16 +04:00
|
|
|
* opal_list_get_end() to ensure that the list is not empty.
|
2004-08-11 20:18:52 +04:00
|
|
|
*
|
|
|
|
* This is an inlined function in compilers that support inlining, so
|
|
|
|
* it's usually a cheap operation.
|
2003-12-22 19:29:21 +03:00
|
|
|
*/
|
2005-07-03 20:22:16 +04:00
|
|
|
static inline opal_list_item_t* opal_list_get_first(opal_list_t* list)
|
2004-01-13 03:36:37 +03:00
|
|
|
{
|
2006-07-13 08:56:15 +04:00
|
|
|
opal_list_item_t* item = (opal_list_item_t*)list->opal_list_sentinel.opal_list_next;
|
2005-04-08 19:31:28 +04:00
|
|
|
#if OMPI_ENABLE_DEBUG
|
|
|
|
/* Spot check: ensure that the first item is only on one list */
|
|
|
|
|
2005-07-03 20:22:16 +04:00
|
|
|
assert(1 == item->opal_list_item_refcount);
|
|
|
|
assert( list == item->opal_list_item_belong_to );
|
2005-04-08 19:31:28 +04:00
|
|
|
#endif
|
|
|
|
|
2005-04-13 09:14:21 +04:00
|
|
|
return item;
|
2004-01-13 03:36:37 +03:00
|
|
|
}
|
2003-12-22 19:29:21 +03:00
|
|
|
|
2004-08-11 20:18:52 +04:00
|
|
|
/**
|
|
|
|
* Return the last item on the list (does not remove it).
|
|
|
|
*
|
|
|
|
* @param list The list container
|
|
|
|
*
|
|
|
|
* @returns A pointer to the last item on the list
|
|
|
|
*
|
|
|
|
* This is an O(1) operation to return the last item on the list. It
|
|
|
|
* should be compared against the returned value from
|
2005-07-03 20:22:16 +04:00
|
|
|
* opal_list_get_begin() to ensure that the list is not empty.
|
2004-08-11 20:18:52 +04:00
|
|
|
*
|
|
|
|
* This is an inlined function in compilers that support inlining, so
|
|
|
|
* it's usually a cheap operation.
|
2003-12-22 19:29:21 +03:00
|
|
|
*/
|
2005-07-03 20:22:16 +04:00
|
|
|
static inline opal_list_item_t* opal_list_get_last(opal_list_t* list)
|
2004-01-13 03:36:37 +03:00
|
|
|
{
|
2006-07-13 08:56:15 +04:00
|
|
|
opal_list_item_t* item = (opal_list_item_t *)list->opal_list_sentinel.opal_list_prev;
|
2005-04-08 19:31:28 +04:00
|
|
|
#if OMPI_ENABLE_DEBUG
|
|
|
|
/* Spot check: ensure that the last item is only on one list */
|
|
|
|
|
2005-07-03 20:22:16 +04:00
|
|
|
assert( 1 == item->opal_list_item_refcount );
|
|
|
|
assert( list == item->opal_list_item_belong_to );
|
2005-04-08 19:31:28 +04:00
|
|
|
#endif
|
|
|
|
|
2005-04-13 09:14:21 +04:00
|
|
|
return item;
|
2004-01-13 03:36:37 +03:00
|
|
|
}
|
|
|
|
|
2004-08-11 20:18:52 +04:00
|
|
|
/**
|
|
|
|
* Return the beginning of the list; an invalid list entry suitable
|
|
|
|
* for comparison only.
|
|
|
|
*
|
|
|
|
* @param list The list container
|
|
|
|
*
|
|
|
|
* @returns A pointer to the beginning of the list.
|
|
|
|
*
|
|
|
|
* This is an O(1) operation to return the beginning of the list.
|
|
|
|
* Similar to the STL, this is a special invalid list item -- it
|
|
|
|
* should \em not be used for storage. It is only suitable for
|
|
|
|
* comparison to other items in the list to see if they are valid or
|
|
|
|
* not; it's ususally used when iterating through the items in a list.
|
|
|
|
*
|
|
|
|
* This is an inlined function in compilers that support inlining, so
|
|
|
|
* it's usually a cheap operation.
|
2004-01-21 02:19:11 +03:00
|
|
|
*/
|
2005-07-03 20:22:16 +04:00
|
|
|
static inline opal_list_item_t* opal_list_get_begin(opal_list_t* list)
|
2004-01-21 02:19:11 +03:00
|
|
|
{
|
2006-07-13 08:56:15 +04:00
|
|
|
return &(list->opal_list_sentinel);
|
2004-01-21 02:19:11 +03:00
|
|
|
}
|
|
|
|
|
2004-08-11 20:18:52 +04:00
|
|
|
/**
|
|
|
|
* Return the end of the list; an invalid list entry suitable for
|
|
|
|
* comparison only.
|
|
|
|
*
|
|
|
|
* @param list The list container
|
|
|
|
*
|
|
|
|
* @returns A pointer to the end of the list.
|
|
|
|
*
|
|
|
|
* This is an O(1) operation to return the end of the list.
|
|
|
|
* Similar to the STL, this is a special invalid list item -- it
|
|
|
|
* should \em not be used for storage. It is only suitable for
|
|
|
|
* comparison to other items in the list to see if they are valid or
|
|
|
|
* not; it's ususally used when iterating through the items in a list.
|
|
|
|
*
|
|
|
|
* This is an inlined function in compilers that support inlining, so
|
|
|
|
* it's usually a cheap operation.
|
2004-01-13 03:36:37 +03:00
|
|
|
*/
|
2005-07-03 20:22:16 +04:00
|
|
|
static inline opal_list_item_t* opal_list_get_end(opal_list_t* list)
|
2004-01-13 03:36:37 +03:00
|
|
|
{
|
2006-07-13 08:56:15 +04:00
|
|
|
return &(list->opal_list_sentinel);
|
2004-01-13 03:36:37 +03:00
|
|
|
}
|
2003-12-22 19:29:21 +03:00
|
|
|
|
2004-08-17 23:31:07 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the number of items in a list
|
|
|
|
*
|
|
|
|
* @param list The list container
|
|
|
|
*
|
|
|
|
* @returns The size of the list (size_t)
|
|
|
|
*
|
|
|
|
* This is an O(1) lookup to return the size of the list.
|
|
|
|
*
|
|
|
|
* This is an inlined function in compilers that support inlining, so
|
|
|
|
* it's usually a cheap operation.
|
|
|
|
*
|
2004-08-18 02:14:47 +04:00
|
|
|
* \warning The size of the list is cached as part of the list. In
|
2005-07-03 20:22:16 +04:00
|
|
|
* the future, calling \c opal_list_splice or \c opal_list_join may
|
2004-08-18 02:14:47 +04:00
|
|
|
* result in this function recomputing the list size, which would be
|
2005-07-03 20:22:16 +04:00
|
|
|
* an O(N) operation. If \c opal_list_splice or \c opal_list_join is
|
2004-08-18 02:14:47 +04:00
|
|
|
* never called on the specified list, this function will always be
|
|
|
|
* O(1).
|
2004-08-17 23:31:07 +04:00
|
|
|
*/
|
2005-07-03 20:22:16 +04:00
|
|
|
static inline size_t opal_list_get_size(opal_list_t* list)
|
2004-08-17 23:31:07 +04:00
|
|
|
{
|
|
|
|
#if OMPI_ENABLE_DEBUG && 0
|
|
|
|
/* not sure if we really want this running in devel, as it does
|
|
|
|
* slow things down. Wanted for development of splice / join to
|
|
|
|
* make sure length was reset properly
|
|
|
|
*/
|
|
|
|
size_t check_len = 0;
|
2005-07-03 20:22:16 +04:00
|
|
|
opal_list_item_t *item;
|
2004-08-17 23:31:07 +04:00
|
|
|
|
2005-07-03 20:22:16 +04:00
|
|
|
for (item = opal_list_get_first(list) ;
|
|
|
|
item != opal_list_get_end(list) ;
|
|
|
|
item = opal_list_get_next(item)) {
|
2004-08-17 23:31:07 +04:00
|
|
|
check_len++;
|
|
|
|
}
|
|
|
|
|
2005-07-03 20:22:16 +04:00
|
|
|
if (check_len != list->opal_list_length) {
|
|
|
|
fprintf(stderr," Error :: opal_list_get_size - opal_list_length does not match actual list length\n");
|
2004-08-17 23:31:07 +04:00
|
|
|
fflush(stderr);
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2005-07-03 20:22:16 +04:00
|
|
|
return list->opal_list_length;
|
2004-08-17 23:31:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-08-11 20:18:52 +04:00
|
|
|
/**
|
|
|
|
* Remove an item from a list.
|
|
|
|
*
|
|
|
|
* @param list The list container
|
|
|
|
* @param item The item to remove
|
|
|
|
*
|
|
|
|
* @returns A pointer to the item on the list previous to the one
|
|
|
|
* that was removed.
|
|
|
|
*
|
|
|
|
* This is an O(1) operation to remove an item from the list. The
|
|
|
|
* forward / reverse pointers in the list are updated and the item is
|
|
|
|
* removed. The list item that is returned is now "owned" by the
|
|
|
|
* caller -- they are responsible for OBJ_RELEASE()'ing it.
|
|
|
|
*
|
|
|
|
* If debugging is enabled (specifically, if --enable-debug was used
|
|
|
|
* to configure Open MPI), this is an O(N) operation because it checks
|
|
|
|
* to see if the item is actually in the list first.
|
|
|
|
*
|
|
|
|
* This is an inlined function in compilers that support inlining, so
|
|
|
|
* it's usually a cheap operation.
|
2004-01-14 02:26:14 +03:00
|
|
|
*/
|
2005-07-03 20:22:16 +04:00
|
|
|
static inline opal_list_item_t *opal_list_remove_item
|
|
|
|
(opal_list_t *list, opal_list_item_t *item)
|
2004-01-14 04:02:18 +03:00
|
|
|
{
|
2004-06-07 19:33:53 +04:00
|
|
|
#if OMPI_ENABLE_DEBUG
|
2005-07-03 20:22:16 +04:00
|
|
|
opal_list_item_t *item_ptr;
|
2005-04-08 19:31:28 +04:00
|
|
|
bool found = false;
|
2004-01-14 02:26:14 +03:00
|
|
|
|
|
|
|
/* check to see that the item is in the list */
|
2005-07-03 20:22:16 +04:00
|
|
|
for (item_ptr = opal_list_get_first(list);
|
|
|
|
item_ptr != opal_list_get_end(list);
|
|
|
|
item_ptr = (opal_list_item_t *)(item_ptr->opal_list_next)) {
|
|
|
|
if (item_ptr == (opal_list_item_t *) item) {
|
2004-01-18 01:58:12 +03:00
|
|
|
found = true;
|
2004-01-14 02:26:14 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2004-01-18 01:58:12 +03:00
|
|
|
if (!found) {
|
2005-07-03 20:22:16 +04:00
|
|
|
fprintf(stderr," Warning :: opal_list_remove_item - the item %p is not on the list %p \n",(void*) item, (void*) list);
|
2004-01-14 02:26:14 +03:00
|
|
|
fflush(stderr);
|
2005-07-03 20:22:16 +04:00
|
|
|
return (opal_list_item_t *)NULL;
|
2004-01-14 02:26:14 +03:00
|
|
|
}
|
2005-04-08 19:31:28 +04:00
|
|
|
|
2005-07-03 20:22:16 +04:00
|
|
|
assert( list == item->opal_list_item_belong_to );
|
2004-01-14 02:26:14 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* reset next pointer of previous element */
|
2005-07-03 20:22:16 +04:00
|
|
|
item->opal_list_prev->opal_list_next=item->opal_list_next;
|
2004-01-14 02:26:14 +03:00
|
|
|
|
|
|
|
/* reset previous pointer of next element */
|
2005-07-03 20:22:16 +04:00
|
|
|
item->opal_list_next->opal_list_prev=item->opal_list_prev;
|
2004-01-14 02:26:14 +03:00
|
|
|
|
2005-07-03 20:22:16 +04:00
|
|
|
list->opal_list_length--;
|
2005-04-08 19:31:28 +04:00
|
|
|
|
|
|
|
#if OMPI_ENABLE_DEBUG
|
|
|
|
/* Spot check: ensure that this item is still only on one list */
|
|
|
|
|
2005-07-04 02:45:48 +04:00
|
|
|
OPAL_THREAD_ADD32( &(item->opal_list_item_refcount), -1 );
|
2005-07-03 20:22:16 +04:00
|
|
|
assert(0 == item->opal_list_item_refcount);
|
|
|
|
item->opal_list_item_belong_to = NULL;
|
2005-04-08 19:31:28 +04:00
|
|
|
#endif
|
|
|
|
|
2005-07-03 20:22:16 +04:00
|
|
|
return (opal_list_item_t *)item->opal_list_prev;
|
2004-01-14 02:26:14 +03:00
|
|
|
}
|
2003-12-22 19:29:21 +03:00
|
|
|
|
2004-05-19 01:06:11 +04:00
|
|
|
|
2004-08-11 20:18:52 +04:00
|
|
|
/**
|
|
|
|
* Append an item to the end of the list.
|
|
|
|
*
|
|
|
|
* @param list The list container
|
|
|
|
* @param item The item to append
|
|
|
|
*
|
|
|
|
* This is an O(1) operation to append an item to the end of a list.
|
2005-07-03 20:22:16 +04:00
|
|
|
* The opal_list_item_t is not OBJ_RETAIN()'ed; it is assumed that
|
2004-08-11 20:18:52 +04:00
|
|
|
* "ownership" of the item is passed from the caller to the list.
|
|
|
|
*
|
|
|
|
* This is an inlined function in compilers that support inlining, so
|
|
|
|
* it's usually a cheap operation.
|
|
|
|
*/
|
2005-04-13 09:14:21 +04:00
|
|
|
|
|
|
|
#if OMPI_ENABLE_DEBUG
|
2005-07-03 20:22:16 +04:00
|
|
|
#define opal_list_append(l,i) \
|
|
|
|
_opal_list_append(l,i,__FILE__,__LINE__)
|
2005-04-13 09:14:21 +04:00
|
|
|
#else
|
2005-07-03 20:22:16 +04:00
|
|
|
#define opal_list_append(l,i) \
|
|
|
|
_opal_list_append(l,i)
|
2005-04-13 09:14:21 +04:00
|
|
|
#endif /* OMPI_ENABLE_DEBUG */
|
|
|
|
|
2005-07-03 20:22:16 +04:00
|
|
|
static inline void _opal_list_append(opal_list_t *list, opal_list_item_t *item
|
2005-04-13 09:14:21 +04:00
|
|
|
#if OMPI_ENABLE_DEBUG
|
2008-01-16 02:50:30 +03:00
|
|
|
, const char* FILE_NAME, int LINENO
|
2005-04-13 09:14:21 +04:00
|
|
|
#endif /* OMPI_ENABLE_DEBUG */
|
|
|
|
)
|
2004-08-11 20:18:52 +04:00
|
|
|
{
|
2006-07-13 08:56:15 +04:00
|
|
|
opal_list_item_t* sentinel = &(list->opal_list_sentinel);
|
2005-04-08 19:31:28 +04:00
|
|
|
#if OMPI_ENABLE_DEBUG
|
|
|
|
/* Spot check: ensure that this item is previously on no lists */
|
|
|
|
|
2005-07-03 20:22:16 +04:00
|
|
|
assert(0 == item->opal_list_item_refcount);
|
|
|
|
assert( NULL == item->opal_list_item_belong_to );
|
2007-01-30 09:34:38 +03:00
|
|
|
item->super.cls_init_file_name = FILE_NAME;
|
2005-04-13 09:14:21 +04:00
|
|
|
item->super.cls_init_lineno = LINENO;
|
2005-04-08 19:31:28 +04:00
|
|
|
#endif
|
|
|
|
|
2004-08-11 20:18:52 +04:00
|
|
|
/* set new element's previous pointer */
|
2006-07-13 08:56:15 +04:00
|
|
|
item->opal_list_prev = sentinel->opal_list_prev;
|
2003-12-22 19:29:21 +03:00
|
|
|
|
2004-08-11 20:18:52 +04:00
|
|
|
/* reset previous pointer on current last element */
|
2006-07-13 08:56:15 +04:00
|
|
|
sentinel->opal_list_prev->opal_list_next = item;
|
2003-12-22 19:29:21 +03:00
|
|
|
|
2004-08-11 20:18:52 +04:00
|
|
|
/* reset new element's next pointer */
|
2006-07-13 08:56:15 +04:00
|
|
|
item->opal_list_next = sentinel;
|
2004-05-19 01:06:11 +04:00
|
|
|
|
2004-08-11 20:18:52 +04:00
|
|
|
/* reset the list's tail element previous pointer */
|
2006-07-13 08:56:15 +04:00
|
|
|
sentinel->opal_list_prev = item;
|
2004-05-19 01:06:11 +04:00
|
|
|
|
2004-08-11 20:18:52 +04:00
|
|
|
/* increment list element counter */
|
2005-07-03 20:22:16 +04:00
|
|
|
list->opal_list_length++;
|
2005-04-08 19:31:28 +04:00
|
|
|
|
|
|
|
#if OMPI_ENABLE_DEBUG
|
|
|
|
/* Spot check: ensure this item is only on the list that we just
|
|
|
|
appended it to */
|
|
|
|
|
2005-07-04 02:45:48 +04:00
|
|
|
OPAL_THREAD_ADD32( &(item->opal_list_item_refcount), 1 );
|
2005-07-03 20:22:16 +04:00
|
|
|
assert(1 == item->opal_list_item_refcount);
|
|
|
|
item->opal_list_item_belong_to = list;
|
2005-04-08 19:31:28 +04:00
|
|
|
#endif
|
2004-08-11 20:18:52 +04:00
|
|
|
}
|
2004-05-19 01:06:11 +04:00
|
|
|
|
|
|
|
|
2004-08-11 20:18:52 +04:00
|
|
|
/**
|
|
|
|
* Prepend an item to the beginning of the list.
|
|
|
|
*
|
|
|
|
* @param list The list container
|
|
|
|
* @param item The item to prepend
|
|
|
|
*
|
|
|
|
* This is an O(1) operation to prepend an item to the beginning of a
|
2005-07-03 20:22:16 +04:00
|
|
|
* list. The opal_list_item_t is not OBJ_RETAIN()'ed; it is assumed
|
2004-08-11 20:18:52 +04:00
|
|
|
* that "ownership" of the item is passed from the caller to the list.
|
|
|
|
*
|
|
|
|
* This is an inlined function in compilers that support inlining, so
|
|
|
|
* it's usually a cheap operation.
|
|
|
|
*/
|
2005-07-03 20:22:16 +04:00
|
|
|
static inline void opal_list_prepend(opal_list_t *list,
|
|
|
|
opal_list_item_t *item)
|
2004-08-11 20:18:52 +04:00
|
|
|
{
|
2006-07-13 08:56:15 +04:00
|
|
|
opal_list_item_t* sentinel = &(list->opal_list_sentinel);
|
2005-04-08 19:31:28 +04:00
|
|
|
#if OMPI_ENABLE_DEBUG
|
|
|
|
/* Spot check: ensure that this item is previously on no lists */
|
|
|
|
|
2005-07-03 20:22:16 +04:00
|
|
|
assert(0 == item->opal_list_item_refcount);
|
|
|
|
assert( NULL == item->opal_list_item_belong_to );
|
2005-04-08 19:31:28 +04:00
|
|
|
#endif
|
|
|
|
|
2004-08-11 20:18:52 +04:00
|
|
|
/* reset item's next pointer */
|
2006-07-13 08:56:15 +04:00
|
|
|
item->opal_list_next = sentinel->opal_list_next;
|
2004-08-11 20:18:52 +04:00
|
|
|
|
|
|
|
/* reset item's previous pointer */
|
2006-07-13 08:56:15 +04:00
|
|
|
item->opal_list_prev = sentinel;
|
2004-08-11 20:18:52 +04:00
|
|
|
|
|
|
|
/* reset previous first element's previous poiner */
|
2006-07-13 08:56:15 +04:00
|
|
|
sentinel->opal_list_next->opal_list_prev = item;
|
2004-08-11 20:18:52 +04:00
|
|
|
|
|
|
|
/* reset head's next pointer */
|
2006-07-13 08:56:15 +04:00
|
|
|
sentinel->opal_list_next = item;
|
2004-08-11 20:18:52 +04:00
|
|
|
|
|
|
|
/* increment list element counter */
|
2005-07-03 20:22:16 +04:00
|
|
|
list->opal_list_length++;
|
2005-04-08 19:31:28 +04:00
|
|
|
|
|
|
|
#if OMPI_ENABLE_DEBUG
|
|
|
|
/* Spot check: ensure this item is only on the list that we just
|
|
|
|
prepended it to */
|
|
|
|
|
2005-07-04 02:45:48 +04:00
|
|
|
OPAL_THREAD_ADD32( &(item->opal_list_item_refcount), 1 );
|
2005-07-03 20:22:16 +04:00
|
|
|
assert(1 == item->opal_list_item_refcount);
|
|
|
|
item->opal_list_item_belong_to = list;
|
2005-04-08 19:31:28 +04:00
|
|
|
#endif
|
2004-08-11 20:18:52 +04:00
|
|
|
}
|
2003-12-22 19:29:21 +03:00
|
|
|
|
|
|
|
|
2004-08-11 20:18:52 +04:00
|
|
|
/**
|
|
|
|
* Remove the first item from the list and return it.
|
|
|
|
*
|
|
|
|
* @param list The list container
|
|
|
|
*
|
|
|
|
* @returns The first item on the list. If the list is empty,
|
|
|
|
* NULL will be returned
|
|
|
|
*
|
|
|
|
* This is an O(1) operation to return the first item on the list. If
|
|
|
|
* the list is not empty, a pointer to the first item in the list will
|
|
|
|
* be returned. Ownership of the item is transferred from the list to
|
|
|
|
* the caller; no calls to OBJ_RETAIN() or OBJ_RELEASE() are invoked.
|
|
|
|
*
|
|
|
|
* This is an inlined function in compilers that support inlining, so
|
|
|
|
* it's usually a cheap operation.
|
|
|
|
*/
|
2005-07-03 20:22:16 +04:00
|
|
|
static inline opal_list_item_t *opal_list_remove_first(opal_list_t *list)
|
2004-08-11 20:18:52 +04:00
|
|
|
{
|
|
|
|
/* Removes and returns first item on list.
|
|
|
|
Caller now owns the item and should release the item
|
|
|
|
when caller is done with it.
|
|
|
|
*/
|
2005-07-03 20:22:16 +04:00
|
|
|
volatile opal_list_item_t *item;
|
|
|
|
if ( 0 == list->opal_list_length ) {
|
|
|
|
return (opal_list_item_t *)NULL;
|
2004-08-11 20:18:52 +04:00
|
|
|
}
|
|
|
|
|
2005-04-08 19:31:28 +04:00
|
|
|
#if OMPI_ENABLE_DEBUG
|
|
|
|
/* Spot check: ensure that the first item is only on this list */
|
|
|
|
|
2006-07-13 08:56:15 +04:00
|
|
|
assert(1 == list->opal_list_sentinel.opal_list_next->opal_list_item_refcount);
|
2005-04-08 19:31:28 +04:00
|
|
|
#endif
|
|
|
|
|
2004-08-11 20:18:52 +04:00
|
|
|
/* reset list length counter */
|
2005-07-03 20:22:16 +04:00
|
|
|
list->opal_list_length--;
|
2004-08-11 20:18:52 +04:00
|
|
|
|
|
|
|
/* get pointer to first element on the list */
|
2006-07-13 08:56:15 +04:00
|
|
|
item = list->opal_list_sentinel.opal_list_next;
|
2004-08-11 20:18:52 +04:00
|
|
|
|
|
|
|
/* reset previous pointer of next item on the list */
|
2006-07-13 08:56:15 +04:00
|
|
|
item->opal_list_next->opal_list_prev = item->opal_list_prev;
|
2004-08-11 20:18:52 +04:00
|
|
|
|
|
|
|
/* reset the head next pointer */
|
2006-07-13 08:56:15 +04:00
|
|
|
list->opal_list_sentinel.opal_list_next = item->opal_list_next;
|
2004-08-11 20:18:52 +04:00
|
|
|
|
2004-06-07 19:33:53 +04:00
|
|
|
#if OMPI_ENABLE_DEBUG
|
2005-07-03 20:22:16 +04:00
|
|
|
assert( list == item->opal_list_item_belong_to );
|
|
|
|
item->opal_list_item_belong_to = NULL;
|
|
|
|
item->opal_list_prev=(opal_list_item_t *)NULL;
|
|
|
|
item->opal_list_next=(opal_list_item_t *)NULL;
|
2005-04-08 19:31:28 +04:00
|
|
|
|
|
|
|
/* Spot check: ensure that the item we're returning is now on no
|
|
|
|
lists */
|
|
|
|
|
2005-07-04 02:45:48 +04:00
|
|
|
OPAL_THREAD_ADD32( &(item->opal_list_item_refcount), -1 );
|
2005-07-03 20:22:16 +04:00
|
|
|
assert(0 == item->opal_list_item_refcount);
|
2004-05-19 01:06:11 +04:00
|
|
|
#endif
|
2005-04-08 19:31:28 +04:00
|
|
|
|
2005-07-03 20:22:16 +04:00
|
|
|
return (opal_list_item_t *) item;
|
2004-08-11 20:18:52 +04:00
|
|
|
}
|
2003-12-22 19:29:21 +03:00
|
|
|
|
2004-05-19 01:06:11 +04:00
|
|
|
|
2004-08-11 20:18:52 +04:00
|
|
|
/**
|
|
|
|
* Remove the last item from the list and return it.
|
|
|
|
*
|
|
|
|
* @param list The list container
|
|
|
|
*
|
|
|
|
* @returns The last item on the list. If the list is empty,
|
|
|
|
* NULL will be returned
|
|
|
|
*
|
|
|
|
* This is an O(1) operation to return the last item on the list. If
|
|
|
|
* the list is not empty, a pointer to the last item in the list will
|
|
|
|
* be returned. Ownership of the item is transferred from the list to
|
|
|
|
* the caller; no calls to OBJ_RETAIN() or OBJ_RELEASE() are invoked.
|
|
|
|
*
|
|
|
|
* This is an inlined function in compilers that support inlining, so
|
|
|
|
* it's usually a cheap operation.
|
|
|
|
*/
|
2005-07-03 20:22:16 +04:00
|
|
|
static inline opal_list_item_t *opal_list_remove_last(opal_list_t *list)
|
2004-08-11 20:18:52 +04:00
|
|
|
{
|
|
|
|
/* Removes, releases and returns last item on list.
|
|
|
|
Caller now owns the item and should release the item
|
|
|
|
when caller is done with it.
|
|
|
|
*/
|
2005-07-03 20:22:16 +04:00
|
|
|
volatile opal_list_item_t *item;
|
|
|
|
if ( 0 == list->opal_list_length ) {
|
2006-07-13 08:56:15 +04:00
|
|
|
return (opal_list_item_t *)NULL;
|
2005-04-08 19:31:28 +04:00
|
|
|
}
|
2004-08-11 20:18:52 +04:00
|
|
|
|
2005-04-08 19:31:28 +04:00
|
|
|
#if OMPI_ENABLE_DEBUG
|
|
|
|
/* Spot check: ensure that the first item is only on this list */
|
|
|
|
|
2006-07-13 08:56:15 +04:00
|
|
|
assert(1 == list->opal_list_sentinel.opal_list_prev->opal_list_item_refcount);
|
2005-04-08 19:31:28 +04:00
|
|
|
#endif
|
|
|
|
|
2004-08-11 20:18:52 +04:00
|
|
|
/* reset list length counter */
|
2005-07-03 20:22:16 +04:00
|
|
|
list->opal_list_length--;
|
2004-08-11 20:18:52 +04:00
|
|
|
|
|
|
|
/* get item */
|
2006-07-13 08:56:15 +04:00
|
|
|
item = list->opal_list_sentinel.opal_list_prev;
|
2004-08-11 20:18:52 +04:00
|
|
|
|
|
|
|
/* reset previous pointer on next to last pointer */
|
2006-07-13 08:56:15 +04:00
|
|
|
item->opal_list_prev->opal_list_next = item->opal_list_next;
|
2004-08-11 20:18:52 +04:00
|
|
|
|
|
|
|
/* reset tail's previous pointer */
|
2006-07-13 08:56:15 +04:00
|
|
|
list->opal_list_sentinel.opal_list_prev = item->opal_list_prev;
|
2004-08-11 20:18:52 +04:00
|
|
|
|
2004-06-07 19:33:53 +04:00
|
|
|
#if OMPI_ENABLE_DEBUG
|
2005-07-03 20:22:16 +04:00
|
|
|
assert( list == item->opal_list_item_belong_to );
|
|
|
|
item->opal_list_next = item->opal_list_prev = (opal_list_item_t *)NULL;
|
2005-04-08 19:31:28 +04:00
|
|
|
|
|
|
|
/* Spot check: ensure that the item we're returning is now on no
|
|
|
|
lists */
|
|
|
|
|
2005-07-04 02:45:48 +04:00
|
|
|
OPAL_THREAD_ADD32( &(item->opal_list_item_refcount), -1 );
|
2005-07-03 20:22:16 +04:00
|
|
|
assert(0 == item->opal_list_item_refcount);
|
|
|
|
item->opal_list_item_belong_to = NULL;
|
2004-05-19 01:06:11 +04:00
|
|
|
#endif
|
2005-04-08 19:31:28 +04:00
|
|
|
|
2005-07-03 20:22:16 +04:00
|
|
|
return (opal_list_item_t *) item;
|
2004-08-11 20:18:52 +04:00
|
|
|
}
|
|
|
|
|
2004-09-10 08:54:17 +04:00
|
|
|
/**
|
|
|
|
* Add an item to the list before a given element
|
|
|
|
*
|
|
|
|
* @param list The list container
|
|
|
|
* @param pos List element to insert \c item before
|
|
|
|
* @param item The item to insert
|
|
|
|
*
|
|
|
|
* Inserts \c item before \c pos. This is an O(1) operation.
|
|
|
|
*/
|
2005-07-03 20:22:16 +04:00
|
|
|
static inline void opal_list_insert_pos(opal_list_t *list, opal_list_item_t *pos,
|
|
|
|
opal_list_item_t *item)
|
2004-09-10 08:54:17 +04:00
|
|
|
{
|
2005-04-08 19:31:28 +04:00
|
|
|
#if OMPI_ENABLE_DEBUG
|
|
|
|
/* Spot check: ensure that the item we're insertting is currently
|
|
|
|
not on any list */
|
|
|
|
|
2005-07-03 20:22:16 +04:00
|
|
|
assert(0 == item->opal_list_item_refcount);
|
|
|
|
assert( NULL == item->opal_list_item_belong_to );
|
2005-04-08 19:31:28 +04:00
|
|
|
#endif
|
|
|
|
|
2004-09-10 08:54:17 +04:00
|
|
|
/* point item at the existing elements */
|
2005-07-03 20:22:16 +04:00
|
|
|
item->opal_list_next = pos;
|
|
|
|
item->opal_list_prev = pos->opal_list_prev;
|
2004-09-10 08:54:17 +04:00
|
|
|
|
|
|
|
/* splice into the list */
|
2005-07-03 20:22:16 +04:00
|
|
|
pos->opal_list_prev->opal_list_next = item;
|
|
|
|
pos->opal_list_prev = item;
|
2004-09-10 08:54:17 +04:00
|
|
|
|
|
|
|
/* reset list length counter */
|
2005-07-03 20:22:16 +04:00
|
|
|
list->opal_list_length++;
|
2005-04-08 19:31:28 +04:00
|
|
|
|
|
|
|
#if OMPI_ENABLE_DEBUG
|
|
|
|
/* Spot check: double check that this item is only on the list
|
|
|
|
that we just added it to */
|
|
|
|
|
2005-07-04 02:45:48 +04:00
|
|
|
OPAL_THREAD_ADD32( &(item->opal_list_item_refcount), 1 );
|
2005-07-03 20:22:16 +04:00
|
|
|
assert(1 == item->opal_list_item_refcount);
|
|
|
|
item->opal_list_item_belong_to = list;
|
2005-04-08 19:31:28 +04:00
|
|
|
#endif
|
2004-09-10 08:54:17 +04:00
|
|
|
}
|
2004-05-19 01:06:11 +04:00
|
|
|
|
2004-08-11 20:18:52 +04:00
|
|
|
/**
|
|
|
|
* Add an item to the list at a specific index location in the list.
|
|
|
|
*
|
|
|
|
* @param list The list container
|
|
|
|
* @param item The item to insert
|
|
|
|
* @param index Location to add the item
|
|
|
|
*
|
|
|
|
* @returns true if insertion succeeded; otherwise false
|
|
|
|
*
|
|
|
|
* This is potentially an O(N) operation to traverse down to the
|
|
|
|
* correct location in the list and add an item.
|
|
|
|
*
|
|
|
|
* Example: if idx = 2 and list = item1->item2->item3->item4, then
|
|
|
|
* after insert, list = item1->item2->item->item3->item4.
|
|
|
|
*
|
|
|
|
* If index is greater than the length of the list, no action is
|
|
|
|
* performed and false is returned.
|
|
|
|
*/
|
2006-08-23 04:29:35 +04:00
|
|
|
OPAL_DECLSPEC bool opal_list_insert(opal_list_t *list, opal_list_item_t *item,
|
|
|
|
long long idx);
|
2004-08-17 23:31:07 +04:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Join a list into another list
|
|
|
|
*
|
|
|
|
* @param thislist List container for list being operated on
|
|
|
|
* @param pos List item in \c thislist marking the position before
|
|
|
|
* which items are inserted
|
|
|
|
* @param xlist List container for list being spliced from
|
|
|
|
*
|
|
|
|
* Join a list into another list. All of the elements of \c xlist
|
|
|
|
* are inserted before \c pos and removed from \c xlist.
|
|
|
|
*
|
|
|
|
* This operation is an O(1) operation. Both \c thislist and \c
|
|
|
|
* xlist must be valid list containsers. \c xlist will be empty
|
2005-07-03 20:22:16 +04:00
|
|
|
* but valid after the call. All pointers to \c opal_list_item_t
|
2004-08-17 23:31:07 +04:00
|
|
|
* containers remain valid, including those that point to elements
|
|
|
|
* in \c xlist.
|
|
|
|
*/
|
2006-08-23 04:29:35 +04:00
|
|
|
OPAL_DECLSPEC void opal_list_join(opal_list_t *thislist, opal_list_item_t *pos,
|
|
|
|
opal_list_t *xlist);
|
2004-08-17 23:31:07 +04:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Splice a list into another list
|
|
|
|
*
|
|
|
|
* @param thislist List container for list being operated on
|
|
|
|
* @param pos List item in \c thislist marking the position before
|
|
|
|
* which items are inserted
|
|
|
|
* @param xlist List container for list being spliced from
|
|
|
|
* @param first List item in \c xlist marking the start of elements
|
|
|
|
* to be copied into \c thislist
|
|
|
|
* @param last List item in \c xlist marking the end of elements
|
|
|
|
* to be copied into \c thislist
|
|
|
|
*
|
|
|
|
* Splice a subset of a list into another list. The \c [first,
|
|
|
|
* last) elements of \c xlist are moved into \c thislist,
|
|
|
|
* inserting them before \c pos. \c pos must be a valid iterator
|
|
|
|
* in \c thislist and \c [first, last) must be a valid range in \c
|
|
|
|
* xlist. \c postition must not be in the range \c [first, last).
|
|
|
|
* It is, however, valid for \c xlist and \c thislist to be the
|
|
|
|
* same list.
|
|
|
|
*
|
|
|
|
* This is an O(N) operation because the length of both lists must
|
|
|
|
* be recomputed.
|
|
|
|
*/
|
2006-08-23 04:29:35 +04:00
|
|
|
OPAL_DECLSPEC void opal_list_splice(opal_list_t *thislist, opal_list_item_t *pos,
|
|
|
|
opal_list_t *xlist, opal_list_item_t *first,
|
|
|
|
opal_list_item_t *last);
|
2004-08-17 23:31:07 +04:00
|
|
|
|
2005-03-14 23:57:21 +03:00
|
|
|
/**
|
2005-07-03 20:22:16 +04:00
|
|
|
* Comparison function for opal_list_sort(), below.
|
2005-03-14 23:57:21 +03:00
|
|
|
*
|
2005-07-03 20:22:16 +04:00
|
|
|
* @param a Pointer to a pointer to an opal_list_item_t.
|
2005-03-14 23:57:21 +03:00
|
|
|
* Explanation below.
|
2005-07-03 20:22:16 +04:00
|
|
|
* @param b Pointer to a pointer to an opal_list_item_t.
|
2005-03-14 23:57:21 +03:00
|
|
|
* Explanation below.
|
|
|
|
* @retval 1 if \em a is greater than \em b
|
|
|
|
* @retval 0 if \em a is equal to \em b
|
|
|
|
* @retval 11 if \em a is less than \em b
|
|
|
|
*
|
|
|
|
* This function is invoked by qsort(3) from within
|
2005-07-03 20:22:16 +04:00
|
|
|
* opal_list_sort(). It is important to understand what
|
|
|
|
* opal_list_sort() does before invoking qsort, so go read that
|
2005-03-14 23:57:21 +03:00
|
|
|
* documentation first.
|
|
|
|
*
|
|
|
|
* The important thing to realize here is that a and b will be \em
|
|
|
|
* double pointers to the items that you need to compare. Here's
|
|
|
|
* a sample compare function to illustrate this point:
|
|
|
|
*
|
|
|
|
* \verb
|
2005-07-03 20:22:16 +04:00
|
|
|
* static int compare(opal_list_item_t **a, opal_list_item_t **b)
|
2005-03-14 23:57:21 +03:00
|
|
|
* {
|
|
|
|
* orte_pls_base_cmp_t *aa = *((orte_pls_base_cmp_t **) a);
|
|
|
|
* orte_pls_base_cmp_t *bb = *((orte_pls_base_cmp_t **) b);
|
|
|
|
*
|
|
|
|
* if (bb->priority > aa->priority) {
|
|
|
|
* return 1;
|
|
|
|
* } else if (bb->priority == aa->priority) {
|
|
|
|
* return 0;
|
|
|
|
* } else {
|
|
|
|
* return -1;
|
|
|
|
* }
|
|
|
|
* }
|
|
|
|
* \endverb
|
|
|
|
*/
|
2005-07-03 20:22:16 +04:00
|
|
|
typedef int (*opal_list_item_compare_fn_t)(opal_list_item_t **a,
|
|
|
|
opal_list_item_t **b);
|
2005-03-14 23:57:21 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sort a list with a provided compare function.
|
|
|
|
*
|
|
|
|
* @param list The list to sort
|
|
|
|
* @param compare Compare function
|
|
|
|
*
|
|
|
|
* Put crassly, this function's complexity is O(N) + O(log(N)).
|
|
|
|
* Its algorithm is:
|
|
|
|
*
|
|
|
|
* - remove every item from the list and put the corresponding
|
2005-07-03 20:22:16 +04:00
|
|
|
* (opal_list_item_t*)'s in an array
|
2005-03-14 23:57:21 +03:00
|
|
|
* - call qsort(3) with that array and your compare function
|
|
|
|
* - re-add every element of the now-sorted array to the list
|
|
|
|
*
|
|
|
|
* The resulting list is now ordered. Note, however, that since
|
|
|
|
* an array of pointers is sorted, the comparison function must do
|
2005-07-03 20:22:16 +04:00
|
|
|
* a double de-reference to get to the actual opal_list_item_t (or
|
2005-03-14 23:57:21 +03:00
|
|
|
* whatever the underlying type is). See the documentation of
|
2005-07-03 20:22:16 +04:00
|
|
|
* opal_list_item_compare_fn_t for an example).
|
2005-03-14 23:57:21 +03:00
|
|
|
*/
|
2006-08-23 04:29:35 +04:00
|
|
|
OPAL_DECLSPEC int opal_list_sort(opal_list_t* list, opal_list_item_compare_fn_t compare);
|
2005-03-14 23:57:21 +03:00
|
|
|
|
2004-01-21 02:19:11 +03:00
|
|
|
#if defined(c_plusplus) || defined(__cplusplus)
|
|
|
|
}
|
|
|
|
#endif
|
2003-12-22 19:29:21 +03:00
|
|
|
|
2004-08-11 20:18:52 +04:00
|
|
|
|
|
|
|
|
2005-07-03 20:22:16 +04:00
|
|
|
#endif /* OPAL_LIST_H */
|