IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 9, 2005, 5:56:03 PM (21 years ago)
Author:
Paul Price
Message:

General tidy up through to section ~ 2. Still need to check psString etc.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/doc/pslib/psLibSDRS.tex

    r4199 r4208  
    1 %%% $Id: psLibSDRS.tex,v 1.273 2005-06-09 22:21:06 jhoblitt Exp $
     1%%% $Id: psLibSDRS.tex,v 1.274 2005-06-10 03:56:03 price Exp $
    22\documentclass[panstarrs,spec]{panstarrs}
    33
     
    127127Library (GSL):
    128128
    129 \href{www.gnu.org/software/gsl/}{\tt www.gnu.org/software/gsl});
     129\href{www.gnu.org/software/gsl/}{\tt www.gnu.org/software/gsl};
    130130
    131131\item The sort functions should wrap the system \code{qsort} call
     
    145145fashion in the Pilot Project.  Also, RHL has provided functional
    146146prototype code for the memory management, tracing and message logging
    147 functions (some of which need to be revised), and the data containers
    148 (doubly-linked lists, hashes, arrays).
     147functions (some of which need to be revised), and some of the data
     148containers (doubly-linked lists, hashes, arrays).
    149149
    150150\subsection{Threads}
    151151
    152 Pan-STARRS does not have a strong requirement for multithreading capability.
    153 The memory management functions, defined below, must be written to be
    154 thread-safe.  The use of \code{static} variables should be keep to an absolute
    155 minimum and then only when protected by a ``mutex''.  Cross-thread
    156 synchronization for PSLib's fundamental datatypes (\code{psArray},
    157 \code{psVector}, etc.) is left as an exercise for the end-user.
     152Pan-STARRS does not have a strong requirement for multithreading
     153capability.  The memory management functions, defined below, must be
     154written to be thread-safe.  The use of \code{static} variables should
     155be kept to an absolute minimum and then only when protected by a
     156``mutex''.  Cross-thread synchronization for PSLib's fundamental
     157datatypes (\code{psArray}, \code{psList}, etc.) is left to the end-user.
     158
     159PSLib shall provide some functions and structures that assist in
     160thread-safety, but it is left up to the end-user to employ these.
     161That is, these conveniences are not used internally by PSLib, and so
     162the user should make no assumptions about thread-safety (outside the
     163memory management functions).
    158164
    159165\subsection{Conventions}
     
    204210\subsection{Initialization}
    205211
    206 PSLib shall be initialized by calling \code{psLibInit} by the user
     212PSLib may be initialized by calling \code{psLibInit} by the user
    207213before use.  This enables the library to perform the following tasks
    208214that are required before general use:
     
    219225
    220226\code{timeConfig} specifies the filename of the configuration file
    221 for \code{psTime} metadata
     227for \code{psTime} metadata.
    222228
    223229\subsection{Finalization}
     
    228234
    229235\code{psLibCleanup} shall free memory that was allocated by
    230 \code{psLibInit}, allowing a subsequent search for leaked memory.
     236\code{psLibInit}, allowing a subsequent search for leaked memory (even
     237memory marked as \code{persistent}).
    231238
    232239\subsection{Memory Management}
     
    272279\item
    273280  While debugging complex scientific code, it is very useful to be
    274   able to trace a given data structure as it passes through the
     281  able to trace a specific data structure as it passes through the
    275282  processing pipeline.
    276283
     
    359366list.
    360367
    361 The element \code{freeFunc} specifies the deallocator associated with a
    362 specific block of memory.  If this element is \code{NULL}, the basic
    363 deallocator is used and the memory block must not be a rich data
    364 structure which requires additional freeing functionality.
     368The element \code{freeFunc} specifies the deallocator associated with
     369a specific block of memory.  If this element is \code{NULL}, the basic
     370deallocator (\code{psFree}) is used and the memory block must not be a
     371rich data structure which requires additional freeing functionality
     372(otherwise memory leaks will occur).
    365373
    366374The element \code{id} in the structure is a sequential memory block
     
    384392\code{persistent} to be ignored when identifing memory leaks with
    385393\code{psMemCheckLeaks}.  Private functions shall be provided to test
    386 and set the value of \code{persistent}.
     394and set the value of \code{persistent}:
     395\begin{prototype}
     396void p_psMemSetPersistent(psPtr ptr, bool value);
     397bool p_psMemGetPersistent(psPtr ptr);
     398\end{prototype}
     399
    387400
    388401The \code{psMemBlock} structure element \code{refCounter} is provided
     
    417430components that employ any \code{persistent} memory shall provide a
    418431function that frees all of its \code{persistent} memory (and only that
    419 persistent memory that belongs to that component).
     432persistent memory that belongs to that component), all of which should
     433be called from \code{psLibCleanup}.
    420434
    421435\subsubsection{APIs for Allocating and Freeing}
     
    768782points to a data block with multiple references, this call would only
    769783decrement the counter. 
     784
     785\subsection{Conventions adopted}
     786
     787Only pointers allocated with the PSLib memory functions are compatible
     788with the various PSLib container types (e.g., \code{psList,
     789psMetadata}), because the functions working with the container types
     790search for the attached \code{psMemBlock}.  If a pointer allocated
     791with another memory system (e.g., the system \code{malloc}), or
     792generated by offsetting from another pointer that was allocated with
     793\code{psAlloc}, is used with PSLib, the PSLib functions would falsely
     794determine that memory is corrupted, because of the missing
     795\code{psMemBlock}.
     796
     797To pilot our way through the potential confusion, instead of calling
     798all pointers (of unspecified type) a ``\code{void*}'', we adopt a
     799convention, both in this document and in the source, of referring to a
     800pointer that has a \code{psMemBlock} attached as a \code{psPtr}:
     801
     802\begin{datatype}
     803typedef void* psPtr;
     804\end{dataType}
     805
     806For the same reason, we also adopt a convention of referring to a string
     807that has a \code{psMemBlock} attached as a \code{psString}:
     808
     809\begin{datatype}
     810typedef char* psString;
     811\end{datatype}
     812
     813That is, \code{psPtr} is used in cases where the function requires the
     814use of a pointer of unspecified type allocated with \code{psAlloc},
     815and \code{psString} is used in cases where the function requires the
     816use of a \code{char*} allocated with \code{psAlloc} (e.g., via
     817\code{psStringCopy} or \code{psStringNCopy}).
     818
     819%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     820
     821\subsection{Threads}
     822
     823As pointed out earlier, PSLib makes no guarantees for thread-safety
     824outside of the memory management functions.  Nevertheless, the following
     825facilities are provided as a convenience to the user.
     826
     827Each of the data structures classified as a ``collection'' (i.e.,
     828\code{psList, psHash, psMetadata, psArray, psPixels, psVector,
     829psBitSet}) and \code{psImage} shall contain an additional member,
     830\code{void *lock}, which provides a place for the user to carry around
     831a mutex or semaphore.  This is provided so that the user doesn't have
     832to pass around both the structure and a mutex, or wrap PSLib
     833structures in their own thread-safe structures that contain a mutex.
     834
     835We also define the following conveniences:
     836\begin{datatype}
     837typedef struct {
     838    pthread_mutex_t mutex;
     839} psMutex;
     840\end{datatype}
     841
     842\begin{prototype}
     843psMutex *psMutexAlloc(void);
     844bool psMutexLock(psMutex *mutex);
     845bool psMutexUnlock(psMutex *mutex);
     846\end{prototype}
     847
     848\code{psMutex} simply wraps a POSIX thread mutex (this is necessary in
     849order to use the PS memory management system).
     850
     851\code{psMutexAlloc} shall allocate memory for a \code{psMutex}, and
     852initialise the mutex.  \code{psMutexLock} shall lock the mutex in
     853\code{thread}, and \code{psMutexUnlock} shall unlock the mutex in
     854\code{thread}.  No distinction is made between read and write locks.
     855
     856These functions, in the interests of speed, should be implemented as
     857preprocessor macros.
     858
     859These functions should only be defined if \code{_REENTRANT} is
     860defined, and poisoned otherwise.
     861
     862%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    770863
    771864\subsection{Tracing and Logging}
     
    15111604        psC64 *C64;                     ///< Pointers to complex floating-point data
    15121605    } data;
     1606    void *lock;                         ///< Lock for thread safety
    15131607} psVector;
    15141608\end{datatype}
     
    16251719    const struct psImage *parent;       ///< parent, if a subimage
    16261720    psArray *children;                  ///< children of this region
     1721    void *lock;                         ///< Lock for thread safety
    16271722} psImage;
    16281723\end{datatype}
     
    17561851    const psU32 nalloc;         // Number allocated
    17571852    psPixelCoord *data;         // The pixel coordinates
     1853    void *lock;                         ///< Lock for thread safety
    17581854} psPixels;
    17591855\end{datatype}
     
    18331929    const long nalloc;                  ///< allocated data block
    18341930    void **data;                        ///< pointer to data block
    1835 } psArray;
     1931    void *lock;                         ///< Optional lock for thread safety
     1932}} psArray;
    18361933\end{datatype}
    18371934%
     
    19182015   psListElem *tail;                    ///< last element on list (may be NULL)
    19192016   psArray *iterators;                  ///< array of psListIterator: iteration cursors
     2017   void *lock;                          ///< Optional lock for thread safety
    19202018} psList;
    19212019\end{datatype}
     
    21262224    long n;                             ///< number of buckets
    21272225    psHashBucket **buckets;             ///< the buckets themselves
    2128 } psHash;
     2226    void *lock;                         ///< Optional lock for thread safety
     2227}} psHash;
    21292228\end{datatype}
    21302229%
     
    23342433    long n;                             ///< Number of chars that form the bitset
    23352434    char *bits;                         ///< The bits
    2336 } psBitSet;
     2435    void *lock;                         ///< Optional lock for thread safety
     2436}} psBitSet;
    23372437\end{datatype}
    23382438
     
    25612661    psList *list;                       ///< list of psMetadataItem
    25622662    psHash *hash;                       ///< hash table of the same metadata
    2563 } psMetadata;
     2663    void *lock;                         ///< Optional lock for thread safety
     2664}} psMetadata;
    25642665\end{datatype}
    25652666The type \code{psMetadata} is a container class for metadata. Note
Note: See TracChangeset for help on using the changeset viewer.