IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jan 24, 2007, 12:14:48 PM (19 years ago)
Author:
jhoblitt
Message:

merge jch-memory branch - overhaul of memory subsystem

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/sys/psError.c

    r9730 r11265  
    1111 *  @author Eric Van Alst, MHPCC
    1212 *
    13  *  @version $Revision: 1.41 $ $Name: not supported by cvs2svn $
    14  *  @date $Date: 2006-10-24 22:52:56 $
     13 *  @version $Revision: 1.42 $ $Name: not supported by cvs2svn $
     14 *  @date $Date: 2007-01-24 22:14:48 $
    1515 *
    1616 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
    1717 */
     18
     19#ifdef HAVE_CONFIG_H
     20# include "config.h"
     21#endif
    1822
    1923#include <stdarg.h>
     
    5559    if (psArrayLength(errorStack) < MAX_ERROR_STACK_SIZE) {
    5660        // make the psErr persistent
    57         p_psMemSetPersistent(err, true);
    58         p_psMemSetPersistent(err->msg, true);
    59         p_psMemSetPersistent(err->name, true);
     61        psMemSetPersistent(err, true);
     62        psMemSetPersistent(err->msg, true);
     63        psMemSetPersistent(err->name, true);
    6064
    6165        psArrayAdd(errorStack, 0, err);
     
    8589        // allocate the error stack
    8690        errorStack = psArrayAllocEmpty(MAX_ERROR_STACK_SIZE);
    87         p_psMemSetPersistent(errorStack, true);
    88         p_psMemSetPersistent(errorStack->data, true);
     91        psMemSetPersistent(errorStack, true);
     92        psMemSetPersistent(errorStack->data, true);
    8993        // store this threads error stack
    9094        // note that pthread_setspecifc() does not take a pointer as the first
     
    9397            psAbort(__func__, "pthread_setspecific() failed");
    9498        }
     99    }
     100
     101    return errorStack;
     102}
     103
     104// This function serves the same purpose of psErrorStackGet() accept it does
     105// not alloc the error stack if it DOES NOT already exist.  Unlike
     106// psErrorStackGet(), this function is NOT guarenteed to return a valid pointer
     107// and it's return status must be checked.
     108static psArray *psErrorStackGetNoAlloc(void)
     109{
     110    // check to see if the error stack key has been initialized
     111    pthread_mutex_lock(&lockErrorStack);
     112    if (errorStackKeyInitialized == false) {
     113        return NULL;
     114    }
     115    pthread_mutex_unlock(&lockErrorStack);
     116
     117    // check to see if the error stack for this thread has been allocated
     118    psArray *errorStack = NULL;
     119    if ((errorStack = pthread_getspecific(errorStack_key)) == NULL) {
     120        return NULL;
    95121    }
    96122
     
    237263        psErr *err = errorStack->data[i];
    238264
    239         p_psMemSetPersistent(err, false);
    240         p_psMemSetPersistent(err->msg, false);
    241         p_psMemSetPersistent(err->name, false);
     265        psMemSetPersistent(err, false);
     266        psMemSetPersistent(err->msg, false);
     267        psMemSetPersistent(err->name, false);
    242268    }
    243269
     
    260286}
    261287
     288// This function does not allocate any memory so it is safe to call from inside
     289// of psMemory.c.  Do not allocate memory in function (or call any functions
     290// that do) without first removing it's use from psMemory.c.
    262291void psErrorStackPrintV(FILE *fd, const char *format, va_list va)
    263292{
    264     psArray *errorStack = psErrorStackGet();
     293    psArray *errorStack = psErrorStackGetNoAlloc();
     294    // do nothing if the error stack has not been allocated
     295    if (!errorStack) {
     296        return;
     297    }
    265298
    266299    vfprintf(fd, format, va);
Note: See TracChangeset for help on using the changeset viewer.