IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 22, 2004, 2:19:42 PM (22 years ago)
Author:
desonia
Message:

added thread-safety to dlist and enhanced the implementation to allow smarter use of the list 'cursor'.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/sysUtils/psDList.h

    r484 r506  
    99 *  @author Robert Daniel DeSonia, MHPCC
    1010 *
    11  *  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
    12  *  @date $Date: 2004-04-21 00:15:17 $
     11 *  @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
     12 *  @date $Date: 2004-04-23 00:19:42 $
    1313 *
    1414 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
    1515 */
    1616
    17 /** Special values of index into list */
     17#include <pthread.h>                   // we need a mutex to make this stuff thread safe.
     18
     19/** Special values of index into list
     20 *
     21 *  This list of possible list position values should be contiguous non-positive values ending with
     22 *  PS_DLIST_UNKNOWN.  Any value less-than-or-equal-to PS_DLIST_UNKNOWN is considered a undefined position.
     23 *
     24 */
    1825enum {
    1926    PS_DLIST_HEAD = 0,                  ///< at head
    2027    PS_DLIST_TAIL = -1,                 ///< at tail
    21     PS_DLIST_UNKNOWN = -2,              ///< unknown position
    22     PS_DLIST_PREVIOUS = -3,             ///< previous element
    23     PS_DLIST_CURRENT = -4,              ///< current element
    24     PS_DLIST_NEXT = -5                  ///< next element
     28    PS_DLIST_PREVIOUS = -2,             ///< previous element
     29    PS_DLIST_CURRENT = -3,              ///< current element
     30    PS_DLIST_NEXT = -4,                 ///< next element
     31    PS_DLIST_UNKNOWN = -5               ///< unknown position (should be last in enum list)
    2532};
    2633
     
    3744typedef struct
    3845{
    39     int n;                              ///< number of elements on list
     46    unsigned int size;                  ///< number of elements on list
    4047    psDlistElem* head;                  ///< first element on list (may be NULL)
    4148    psDlistElem* tail;                  ///< last element on list (may be NULL)
    4249    psDlistElem* iter;                  ///< iteration cursor
    43     int iterIndex;
     50    unsigned int iterIndex;             ///< the numeric position of the iteration cursor in the list
     51    pthread_mutex_t lock;               ///< mutex to lock a node during changes
    4452}
    4553psDlist;
     
    5159/** Constructor */
    5260psDlist *psDlistAlloc(
    53     void *data                      ///< initial data item; may be NULL
    54 );
     61    void *data                          ///< initial data item; may be NULL
     62)
     63;
    5564
    5665/** Destructor */
    5766void psDlistFree(
    58     psDlist *list,                  ///< list to destroy
    59     void (*elemFree)(void *)        ///< destructor for data on list
     67    psDlist* restrict list,             ///< list to destroy
     68    void (*elemFree)(void *)            ///< destructor for data on list
    6069);
    6170
    6271/** Add to list */
    63 psDlist *psDlistAdd(
    64     psDlist *list,                  ///< list to add to (may be NULL)
    65     void *data,                     ///< data item to add
    66     int where                       ///< index, PS_DLIST_HEAD, or PS_DLIST_TAIL
     72psDlist* psDlistAdd(
     73    psDlist* restrict list,             ///< list to add to (may be NULL)
     74    void* data,                         ///< data item to add
     75    int where                           ///< index, PS_DLIST_HEAD, or PS_DLIST_TAIL
    6776);
    6877
    6978/** Append to a list */
    70 psDlist *psDlistAppend(
    71     psDlist *list,                  ///< list to append to (may be NULL)
    72     void *data                      ///< data item to add
     79psDlist* psDlistAppend(
     80    psDlist* restrict list,                      ///< list to append to (may be NULL)
     81    void *data                          ///< data item to add
    7382);
    7483
    7584/** Remove from a list */
    76 void *psDlistRemove(
    77     psDlist *list,                  ///< list to remove element from
    78     void *data,                     ///< data item to remove
    79     int which                       ///< index of item, or PS_DLIST_UNKNOWN, PS_DLIST_NEXT, PS_DLIST_PREV
     85void* psDlistRemove(
     86    psDlist* restrict list,             ///< list to remove element from
     87    void *data,                         ///< data item to remove
     88    int which                           ///< index of item, or PS_DLIST_UNKNOWN, PS_DLIST_NEXT, PS_DLIST_PREV
    8089);
    8190
    8291/** Retrieve from a list */
    83 void *psDlistGet(
    84     const psDlist *list,            ///< list to retrieve element from
    85     int which                       ///< index of item, or PS_DLIST_NEXT, PS_DLIST_PREV, PS_DLIST_UNKNOWN
     92void* psDlistGet(
     93    psDlist* restrict list,             ///< list to retrieve element from
     94    int which                           ///< index of item, or PS_DLIST_NEXT, PS_DLIST_PREV, PS_DLIST_UNKNOWN
    8695);
    8796
    8897/** Set the iterator */
    8998void psDlistSetIterator(
    90     psDlist *list,                  ///< list to retrieve element from
    91     int where                       ///< index, PS_DLIST_HEAD, or PS_DLIST_TAIL
     99    psDlist* restrict list,             ///< list to retrieve element from
     100    int where                           ///< index, PS_DLIST_HEAD, or PS_DLIST_TAIL
    92101);
    93102
    94103/** Get next element relative to iter */
    95 void *psDlistGetNext(
    96     psDlist *list                   ///< list to retrieve element from
     104void* psDlistGetNext(
     105    psDlist* restrict list              ///< list to retrieve element from
    97106);
    98107
    99108/** Get current element at iter */
    100 void *psDlistGetCurrent(
    101     psDlist *list                   ///< list to retrieve element from
     109void* psDlistGetCurrent(
     110    psDlist* restrict list              ///< list to retrieve element from
    102111);
    103112
    104113/** Get prev element relative to iter */
    105 void *psDlistGetPrevious(
    106     psDlist *list                   ///< list to retrieve element from
     114void* psDlistGetPrevious(
     115    psDlist* restrict list              ///< list to retrieve element from
    107116);
    108117
     
    110119#if 0
    111120psVoidPtrArray *psDlistToArray(
    112     psDlist *dlist                  ///< List to convert
     121    psDlist *dlist                      ///< List to convert
    113122);
    114123
    115124/** Convert array to a doubly-linked list */
    116125psDlist *psArrayToDlist(
    117     psVoidPtrArray *arr             ///< Array to convert
     126    psVoidPtrArray *arr                 ///< Array to convert
    118127);
    119128#endif
Note: See TracChangeset for help on using the changeset viewer.