IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 8808


Ignore:
Timestamp:
Sep 13, 2006, 11:11:11 AM (20 years ago)
Author:
jhoblitt
Message:

fix fprintf format errors causing compilation errors on x86 but correctly using inttypes.h
fix some whitespace issues

Location:
trunk/psLib/src
Files:
2 edited

Legend:

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

    r8705 r8808  
    88*  @author Robert Lupton, Princeton University
    99*
    10 *  @version $Revision: 1.82 $ $Name: not supported by cvs2svn $
    11 *  @date $Date: 2006-08-30 04:40:56 $
     10*  @version $Revision: 1.83 $ $Name: not supported by cvs2svn $
     11*  @date $Date: 2006-09-13 21:11:11 $
    1212*
    1313*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    3838#define P_PS_MEMMAGIC (psPtr )0xdeadbeef   // Magic number in psMemBlock header
    3939
    40 #define P_PS_LARGE_BLOCK_SIZE 65536        // size where under, we try to recycle
    4140
    4241static psS32 checkMemBlock(const psMemBlock* m, const char *funcName);
     
    5150static bool memory_is_persistent = false;
    5251
    53 #ifdef PS_MEM_USE_RECYCLE               // Only use recycling if this is set
    54 #define N_RECYCLE_BINS 14               // number of recycle bins
    55 #define MAX_RECYCLE 100                 // Maximum number permitted in a recycle bin
    56 static pthread_mutex_t recycleMemBlockListMutex = PTHREAD_MUTEX_INITIALIZER; // Mutex for recycle bins
    57 static const psS32 recycleBinSize[N_RECYCLE_BINS] = // Size of each bin
    58     {
    59         8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, P_PS_LARGE_BLOCK_SIZE
    60     };
    61 // N.B. recycleBinSize should be terminated by P_PS_LARGE_BLOCK_SIZE (simplifies search loops)
    62 static psS32 recycleBinNums[N_RECYCLE_BINS] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; // Number in each bin
    63 static psMemBlock* recycleMemBlockList[N_RECYCLE_BINS] = // Contents of the bins
    64     { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL };
    65 #endif // #ifdef PS_MEM_USE_RECYCLE
    66 
    6752#ifdef PS_MEM_DEBUG
    6853static psMemBlock* deadBlockList;       // a place to put dead memBlocks in debug mode.
     
    7358 */
    7459static psMemId memid = 0;
    75 
    76 /**
    77  *  Default memExhausted callback.
    78  */
    79 static psPtr memExhaustedCallbackDefault(size_t size)
    80 {
    81     #if PS_MEM_USE_RECYCLE
    82     psPtr ptr = NULL;
    83     if (safeThreads) {
    84         pthread_mutex_lock(&recycleMemBlockListMutex);
    85     }
    86     // Attempt to free up everything I can find so I can alloc my ptr
    87     int bin = N_RECYCLE_BINS - 1;       // Recycle bin
    88 
    89     while (bin >= 0 && ptr == NULL) {
    90         while (recycleMemBlockList[bin] != NULL && ptr == NULL) {
    91             psMemBlock *old = recycleMemBlockList[bin];
    92             recycleMemBlockList[bin] = recycleMemBlockList[bin]->nextBlock;
    93             free(old);
    94             ptr = malloc(size);
    95         }
    96         bin--;
    97     }
    98 
    99     if (safeThreads) {
    100         pthread_mutex_unlock(&recycleMemBlockListMutex);
    101     }
    102     return ptr;
    103     #else  // #ifdef PS_MEM_USE_RECYCLE
    104 
    105     return NULL;
    106     #endif // #ifdef PS_MEM_USE_RECYCLE
    107 }
    10860
    10961/*
     
    150102                           const char *funcName)
    151103{
    152     // n.b. since this is called by psMemCheckCorruption while the memblock list is mutex locked,
    153     // we shouldn't call such things as p_psAlloc/p_psFree here.
     104    // n.b. since this is called by psMemCheckCorruption while the memblock
     105    // list is mutex locked, we shouldn't call such things as
     106    // p_psAlloc/p_psFree here.
    154107
    155108    if (m == NULL) {
     
    189142static psMemFreeCallback memFreeCallback = memFreeCallbackDefault;
    190143static psMemProblemCallback memProblemCallback = memProblemCallbackDefault;
    191 static psMemExhaustedCallback memExhaustedCallback = memExhaustedCallbackDefault;
    192 
    193 psMemExhaustedCallback psMemExhaustedCallbackSet(psMemExhaustedCallback func)
    194 {
    195     psMemExhaustedCallback old = memExhaustedCallback;
    196 
    197     if (func != NULL) {
    198         memExhaustedCallback = func;
    199     } else {
    200         memExhaustedCallback = memExhaustedCallbackDefault;
    201     }
    202 
    203     return old;
    204 }
    205144
    206145psMemProblemCallback psMemProblemCallbackSet(psMemProblemCallback func)
     
    277216
    278217    if (safeThreads) {
     218        // LOCK: id
    279219        pthread_mutex_lock(&memIdMutex);
    280220    }
     
    283223
    284224    if (safeThreads) {
     225        // UNLOCK: id
    285226        pthread_mutex_unlock(&memIdMutex);
    286227    }
     
    291232psMemId psMemGetLastId(void)
    292233{
    293     return memid;
     234    psMemId id;
     235
     236    if (safeThreads) {
     237        // LOCK: id
     238        pthread_mutex_lock(&memIdMutex);
     239    }
     240
     241    id = memid;
     242
     243    if (safeThreads) {
     244        // UNLOCK: id
     245        pthread_mutex_unlock(&memIdMutex);
     246    }
     247
     248    return id;
    294249}
    295250
     
    297252{
    298253    psS32 nbad = 0;               // number of bad blocks
    299     psBool failure = false;
    300 
    301     // get exclusive access to the memBlock list to avoid it changing on us while we use it.
    302     //    pthread_mutex_lock(&memBlockListMutex);
     254
     255    // get exclusive access to the memBlock list to avoid it changing on us
     256    // while we use it.
     257    if (safeThreads) {
     258        // LOCK: block list
     259        pthread_mutex_unlock(&memBlockListMutex);
     260    }
    303261
    304262    for (psMemBlock* iter = lastMemBlockAllocated; iter != NULL; iter = iter->nextBlock) {
    305         if (safeThreads) {
    306             pthread_mutex_unlock(&memBlockListMutex);
    307         }
    308         failure = checkMemBlock(iter, __func__);
    309         if (safeThreads) {
    310             pthread_mutex_lock(&memBlockListMutex);
    311         }
    312         if ( failure ) {
     263        if (checkMemBlock(iter, __func__)) {
    313264            nbad++;
    314265
     
    316267
    317268            if (abort_on_error) {
    318                 // release the lock on the memblock list
    319269                if (safeThreads) {
     270                    // UNLOCK: block list
    320271                    pthread_mutex_unlock(&memBlockListMutex);
    321272                }
     
    326277    }
    327278
    328     // release the lock on the memblock list
    329     if (safeThreads) {
     279    if (safeThreads) {
     280        // UNLOCK: block list
    330281        pthread_mutex_unlock(&memBlockListMutex);
    331282    }
     283
    332284    return nbad;
    333285}
     
    427379    psMemBlock *ptr = NULL;
    428380
    429     #ifdef PS_MEM_USE_RECYCLE
    430     // Are we in one of the recycle bins?
    431     int bin = getRecycleBin(size);
    432     if (bin < N_RECYCLE_BINS) {
    433         size = recycleBinSize[bin];     // round-up size to next sized bin.
    434         ptr = recyclePop(bin);          // grab out of the recycle bin
    435     }
    436     #endif // #ifdef PS_MEM_USE_RECYCLE
    437 
    438381    if (ptr == NULL) {
    439382        ptr = malloc(sizeof(psMemBlock) + size + sizeof(psPtr ));
    440383
    441384        if (ptr == NULL) {
    442             ptr = memExhaustedCallback(size);
    443             if (ptr == NULL) {
    444                 psAbort(__func__, "Failed to allocate %zd bytes at %s:%d", size, file, lineno);
    445             }
     385            psAbort(__func__, "Failed to allocate %zd bytes at %s:%d", size, file, lineno);
    446386        }
    447387
     
    533473    ptr = (psMemBlock *)realloc(ptr, sizeof(psMemBlock) + size + sizeof(psPtr));
    534474    if (ptr == NULL) {
    535         ptr = memExhaustedCallback(size);
    536         if (ptr == NULL) {
    537             psAbort(__func__, "Failed to reallocate %zd bytes at %s:%d", size, file, lineno);
    538         }
     475        psAbort(__func__, "Failed to reallocate %zd bytes at %s:%d", size, file, lineno);
    539476    }
    540477
  • trunk/psLib/src/types/psArguments.c

    r8805 r8808  
    77 *  @author David Robbins, MHPCC
    88 *
    9  *  @version $Revision: 1.12 $ $Name: not supported by cvs2svn $
    10  *  @date $Date: 2006-09-13 02:20:15 $
     9 *  @version $Revision: 1.13 $ $Name: not supported by cvs2svn $
     10 *  @date $Date: 2006-09-13 21:11:11 $
    1111 *
    1212 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
    1313 */
    1414
    15 #include<stdio.h>
    16 #include<stdarg.h>
    17 #include<string.h>
     15#include <stdio.h>
     16#include <stdarg.h>
     17#include <string.h>
     18#include <inttypes.h>
     19
    1820#include "psArguments.h"
    1921#include "fitsio.h"
     
    315317        // Print the value
    316318        switch (item->type) {
    317             PRINT_CASE(U8,"%u");
    318             PRINT_CASE(U16,"%u");
    319             PRINT_CASE(U32,"%u");
    320             PRINT_CASE(U64,"%lu");
    321             PRINT_CASE(S8,"%d");
    322             PRINT_CASE(S16,"%d");
    323             PRINT_CASE(S32,"%d");
    324             PRINT_CASE(S64,"%ld");
    325             PRINT_CASE(F32,"%.6e");
    326             PRINT_CASE(F64,"%.6e");
     319            PRINT_CASE(U8, "%u");
     320            PRINT_CASE(U16, "%u");
     321            PRINT_CASE(U32, "%u");
     322            PRINT_CASE(U64, "%" PRIu64);
     323            PRINT_CASE(S8, "%d");
     324            PRINT_CASE(S16, "%d");
     325            PRINT_CASE(S32, "%d");
     326            PRINT_CASE(S64, "%" PRId64);
     327            PRINT_CASE(F32, "%.6e");
     328            PRINT_CASE(F64, "%.6e");
    327329        case PS_DATA_BOOL:
    328330            if (item->data.B) {
Note: See TracChangeset for help on using the changeset viewer.