IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Oct 26, 2004, 2:57:34 PM (22 years ago)
Author:
desonia
Message:

converted native C types to ps Types, where practical.

File:
1 edited

Legend:

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

    r1840 r2204  
    88*  @author Robert Lupton, Princeton University
    99*
    10 *  @version $Revision: 1.41 $ $Name: not supported by cvs2svn $
    11 *  @date $Date: 2004-09-21 22:30:19 $
     10*  @version $Revision: 1.42 $ $Name: not supported by cvs2svn $
     11*  @date $Date: 2004-10-27 00:57:31 $
    1212*
    1313*  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    1818#include <stdlib.h>
    1919#include <stdio.h>
    20 #include <stdbool.h>
    2120#include <stdint.h>
    2221
     
    2827#include "psSysUtilsErrors.h"
    2928
    30 #define P_PS_MEMMAGIC (void *)0xdeadbeef   // Magic number in psMemBlock header
     29#define P_PS_MEMMAGIC (psPtr )0xdeadbeef   // Magic number in psMemBlock header
    3130
    3231#define P_PS_LARGE_BLOCK_SIZE 65536        // size where under, we try to recycle
    3332
    34 static int checkMemBlock(const psMemBlock* m, const char *funcName);
     33static psS32 checkMemBlock(const psMemBlock* m, const char *funcName);
    3534static psMemBlock* lastMemBlockAllocated = NULL;
    3635static pthread_mutex_t memBlockListMutex = PTHREAD_MUTEX_INITIALIZER;
     
    3938static pthread_mutex_t recycleMemBlockListMutex = PTHREAD_MUTEX_INITIALIZER;
    4039
    41 static int recycleBins = 13;
    42 static int recycleBinSize[14] = {
    43                                     8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, P_PS_LARGE_BLOCK_SIZE
    44                                 };
     40static psS32 recycleBins = 13;
     41static psS32 recycleBinSize[14] = {
     42                                      8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, P_PS_LARGE_BLOCK_SIZE
     43                                  };
    4544
    4645// N.B. recycleBinSize should be terminated by P_PS_LARGE_BLOCK_SIZE (simplifies search loops)
     
    6160 *  Default memExhausted callback.
    6261 */
    63 static void *memExhaustedCallbackDefault(size_t size)
    64 {
    65     void *ptr = NULL;
     62static psPtr memExhaustedCallbackDefault(size_t size)
     63{
     64    psPtr ptr = NULL;
    6665
    6766    pthread_mutex_lock(&recycleMemBlockListMutex);
    68     int level = recycleBins - 1;
     67    psS32 level = recycleBins - 1;
    6968
    7069    while (level >= 0 && ptr == NULL) {
     
    9897}
    9998
    100 static void memProblemCallbackDefault(const psMemBlock* ptr, const char *file, int lineno)
     99static void memProblemCallbackDefault(const psMemBlock* ptr, const char *file, psS32 lineno)
    101100{
    102101    if (ptr->refCounter < 1) {
     
    223222 */
    224223
    225 static int checkMemBlock(const psMemBlock* m, const char *funcName)
     224static psS32 checkMemBlock(const psMemBlock* m, const char *funcName)
    226225{
    227226    // n.b. since this is called by psMemCheckCorruption while the memblock list is mutex locked,
     
    248247        return 1;
    249248    }
    250     if (*(void **)((int8_t *) (m + 1) + m->userMemorySize) != P_PS_MEMMAGIC) {
     249    if (*(psPtr *)((int8_t *) (m + 1) + m->userMemorySize) != P_PS_MEMMAGIC) {
    251250        psErrorMsg(PS_ERRORNAME_DOMAIN "checkMemBlock", true, PS_ERR_MEMORY_CORRUPTION,
    252251                   PS_ERRORTEXT_psMemory_OVERFLOW,
     
    258257}
    259258
    260 int psMemCheckCorruption(bool abort_on_error)
    261 {
    262     int nbad = 0;               // number of bad blocks
    263     bool failure = false;
     259psS32 psMemCheckCorruption(psBool abort_on_error)
     260{
     261    psS32 nbad = 0;               // number of bad blocks
     262    psBool failure = false;
    264263
    265264    // get exclusive access to the memBlock list to avoid it changing on us while we use it.
     
    289288}
    290289
    291 void *p_psAlloc(size_t size, const char *file, int lineno)
     290psPtr p_psAlloc(size_t size, const char *file, psS32 lineno)
    292291{
    293292
     
    297296    if (size < P_PS_LARGE_BLOCK_SIZE) {
    298297        // find the bin we need.
    299         int level = 0;
     298        psS32 level = 0;
    300299
    301300        while (size > recycleBinSize[level]) {
     
    323322
    324323    if (ptr == NULL) {
    325         ptr = malloc(sizeof(psMemBlock) + size + sizeof(void *));
     324        ptr = malloc(sizeof(psMemBlock) + size + sizeof(psPtr ));
    326325
    327326        if (ptr == NULL) {
     
    332331        }
    333332
    334         ptr->startblock = P_PS_MEMMAGIC;
    335         ptr->endblock = P_PS_MEMMAGIC;
     333        *(psPtr*)&ptr->startblock = P_PS_MEMMAGIC;
     334        *(psPtr*)&ptr->endblock = P_PS_MEMMAGIC;
    336335        ptr->userMemorySize = size;
    337336        pthread_mutex_init(&ptr->refCounterMutex, NULL);
     
    345344    ptr->freeFcn = NULL;
    346345    ptr->persistent = false;
    347     *(unsigned int *)&ptr->lineno = lineno;
    348     *(void **)((int8_t *) (ptr + 1) + size) = P_PS_MEMMAGIC;
     346    *(psU32 *)&ptr->lineno = lineno;
     347    *(psPtr *)((int8_t *) (ptr + 1) + size) = P_PS_MEMMAGIC;
    349348    ptr->previousBlock = NULL;
    350349
     
    371370}
    372371
    373 void *p_psRealloc(void *vptr, size_t size, const char *file, int lineno)
     372psPtr p_psRealloc(psPtr vptr, size_t size, const char *file, psS32 lineno)
    374373{
    375374    if (vptr == NULL) {
     
    377376    } else {
    378377        psMemBlock* ptr = ((psMemBlock* ) vptr) - 1;
    379         bool isBlockLast = false;
     378        psBool isBlockLast = false;
    380379
    381380        if (checkMemBlock(ptr, __func__) != 0) {
     
    389388        isBlockLast = (ptr == lastMemBlockAllocated);
    390389
    391         ptr = (psMemBlock* ) realloc(ptr, sizeof(psMemBlock) + size + sizeof(void *));
     390        ptr = (psMemBlock* ) realloc(ptr, sizeof(psMemBlock) + size + sizeof(psPtr ));
    392391
    393392        if (ptr == NULL) {
     
    399398
    400399        ptr->userMemorySize = size;
    401         *(void **)((int8_t *) (ptr + 1) + size) = P_PS_MEMMAGIC;
     400        *(psPtr *)((int8_t *) (ptr + 1) + size) = P_PS_MEMMAGIC;
    402401
    403402        if (isBlockLast) {
     
    423422}
    424423
    425 void p_psFree(void *vptr, const char *file, int lineno)
     424void p_psFree(psPtr vptr, const char *file, psS32 lineno)
    426425{
    427426    if (vptr == NULL) {
     
    444443 * Check for memory leaks.
    445444 */
    446 int psMemCheckLeaks(psMemoryId id0, psMemBlock* ** arr, FILE * fd)
    447 {
    448     int nleak = 0;
    449     int j = 0;
     445psS32 psMemCheckLeaks(psMemoryId id0, psMemBlock* ** arr, FILE * fd)
     446{
     447    psS32 nleak = 0;
     448    psS32 j = 0;
    450449    psMemBlock* topBlock = lastMemBlockAllocated;
    451450
     
    499498 */
    500499// return refCounter
    501 psReferenceCount psMemGetRefCounter(void *vptr)
     500psReferenceCount psMemGetRefCounter(psPtr vptr)
    502501{
    503502    psMemBlock* ptr;
    504     unsigned int refCount;
     503    psU32 refCount;
    505504
    506505    if (vptr == NULL) {
     
    522521
    523522// increment and return refCounter
    524 void *p_psMemIncrRefCounter(void *vptr, const char *file, int lineno)
     523psPtr p_psMemIncrRefCounter(psPtr vptr, const char *file, psS32 lineno)
    525524{
    526525    psMemBlock* ptr;
     
    544543
    545544// decrement and return refCounter
    546 void *p_psMemDecrRefCounter(void *vptr, const char *file, int lineno)
     545psPtr p_psMemDecrRefCounter(psPtr vptr, const char *file, psS32 lineno)
    547546{
    548547    if (vptr == NULL) {
     
    593592        if (ptr->userMemorySize < P_PS_LARGE_BLOCK_SIZE) {
    594593
    595             int level = 1;
     594            psS32 level = 1;
    596595
    597596            while (ptr->userMemorySize >= recycleBinSize[level]) {
     
    635634}
    636635
    637 void p_psMemSetDeallocator(void *vptr, psFreeFcn freeFcn)
     636void p_psMemSetDeallocator(psPtr vptr, psFreeFcn freeFcn)
    638637{
    639638    if (vptr == NULL) {
     
    650649
    651650}
    652 psFreeFcn p_psMemGetDeallocator(void *vptr)
     651psFreeFcn p_psMemGetDeallocator(psPtr vptr)
    653652{
    654653    if (vptr == NULL) {
     
    665664}
    666665
    667 bool p_psMemGetPersistent(void *vptr)
     666psBool p_psMemGetPersistent(psPtr vptr)
    668667{
    669668    if (vptr == NULL) {
     
    680679}
    681680
    682 void p_psMemSetPersistent(void *vptr,bool value)
     681void p_psMemSetPersistent(psPtr vptr,psBool value)
    683682{
    684683    if (vptr == NULL) {
Note: See TracChangeset for help on using the changeset viewer.