pike.git / src / block_alloc.h

version» Context lines:

pike.git/src/block_alloc.h:1: - /* $Id: block_alloc.h,v 1.32 2001/08/30 22:27:49 mast Exp $ */ + /* $Id: block_alloc.h,v 1.33 2001/09/01 00:26:52 hubbe Exp $ */   #undef PRE_INIT_BLOCK   #undef INIT_BLOCK   #undef EXIT_BLOCK   #undef BLOCK_ALLOC   #undef PTR_HASH_ALLOC   #undef COUNT_BLOCK   #undef COUNT_OTHER      #define PRE_INIT_BLOCK(X)   #define INIT_BLOCK(X)   #define EXIT_BLOCK(X)   #define COUNT_BLOCK(X)   #define COUNT_OTHER()      #ifdef PIKE_RUN_UNLOCKED   #include "threads.h" -  +  + /* Block Alloc UnLocked */ + #define BA_UL(X) PIKE_CONCAT(X,_unlocked) + #define BA_STATIC static + #else + #define BA_UL(X) X + #define BA_STATIC   #endif      #define BLOCK_ALLOC(DATA,BSIZE) \    \   struct PIKE_CONCAT(DATA,_block) \   { \    struct PIKE_CONCAT(DATA,_block) *next; \    struct DATA x[BSIZE]; \   }; \    \   static struct PIKE_CONCAT(DATA,_block) *PIKE_CONCAT(DATA,_blocks)=0; \   static struct DATA *PIKE_CONCAT3(free_,DATA,s)=(struct DATA *)-1; \   DO_IF_RUN_UNLOCKED(static PIKE_MUTEX_T PIKE_CONCAT(DATA,_mutex);) \    \ - static struct DATA *PIKE_CONCAT3(alloc_,DATA,_unlocked)(void) \ + BA_STATIC struct DATA *BA_UL(PIKE_CONCAT(alloc_,DATA))(void) \   { \    struct DATA *tmp; \    if(!PIKE_CONCAT3(free_,DATA,s)) \    { \    struct PIKE_CONCAT(DATA,_block) *n; \    int e; \    n=(struct PIKE_CONCAT(DATA,_block) *) \    malloc(sizeof(struct PIKE_CONCAT(DATA,_block))); \    if(!n) \    { \
pike.git/src/block_alloc.h:58:    fatal("Block alloc not initialized.\n"); \    ) \    \    tmp=PIKE_CONCAT3(free_,DATA,s); \    PIKE_CONCAT3(free_,DATA,s)=(struct DATA *)tmp->BLOCK_ALLOC_NEXT; \    DO_IF_DMALLOC( dmalloc_register(tmp,sizeof(struct DATA), DMALLOC_LOCATION()); )\    INIT_BLOCK(tmp); \    return tmp; \   } \    \ + DO_IF_RUN_UNLOCKED( \   struct DATA *PIKE_CONCAT(alloc_,DATA)(void) \   { \    struct DATA *ret; \    DO_IF_RUN_UNLOCKED(mt_lock(&PIKE_CONCAT(DATA,_mutex))); \    ret=PIKE_CONCAT3(alloc_,DATA,_unlocked)(); \    DO_IF_RUN_UNLOCKED(mt_unlock(&PIKE_CONCAT(DATA,_mutex))); \    return ret; \ - } \ + }) \    \ -  + DO_IF_RUN_UNLOCKED( \   void PIKE_CONCAT3(really_free_,DATA,_unlocked)(struct DATA *d) \   { \    EXIT_BLOCK(d); \    DO_IF_DMALLOC( dmalloc_unregister(d, 1); ) \    d->BLOCK_ALLOC_NEXT = (void *)PIKE_CONCAT3(free_,DATA,s); \    PRE_INIT_BLOCK(d); \    PIKE_CONCAT3(free_,DATA,s)=d; \ - } \ + }) \    \   void PIKE_CONCAT(really_free_,DATA)(struct DATA *d) \   { \    EXIT_BLOCK(d); \    DO_IF_RUN_UNLOCKED(mt_lock(&PIKE_CONCAT(DATA,_mutex))); \    DO_IF_DMALLOC( dmalloc_unregister(d, 1); ) \    d->BLOCK_ALLOC_NEXT = (void *)PIKE_CONCAT3(free_,DATA,s); \    PRE_INIT_BLOCK(d); \    PIKE_CONCAT3(free_,DATA,s)=d; \    DO_IF_RUN_UNLOCKED(mt_unlock(&PIKE_CONCAT(DATA,_mutex))); \
pike.git/src/block_alloc.h:246:    PIKE_CONCAT(num_,DATA)++; \    \    if(( PIKE_CONCAT(num_,DATA)>>2 ) >= \    PIKE_CONCAT(DATA,_hash_table_size)) \    { \    PIKE_CONCAT(DATA,_rehash)(); \    hval=(size_t)ptr; \    hval%=PIKE_CONCAT(DATA,_hash_table_size); \    } \    \ -  p=PIKE_CONCAT3(alloc_,DATA,_unlocked)(); \ +  p=BA_UL(PIKE_CONCAT(alloc_,DATA))(); \    p->data=ptr; \    p->BLOCK_ALLOC_NEXT=PIKE_CONCAT(DATA,_hash_table)[hval]; \    PIKE_CONCAT(DATA,_hash_table)[hval]=p; \    return p; \   } \    \   struct DATA *PIKE_CONCAT(make_,DATA)(void *ptr, size_t hval) \   { \    struct DATA *p; \    DO_IF_RUN_UNLOCKED(mt_lock(&PIKE_CONCAT(DATA,_mutex))); \
pike.git/src/block_alloc.h:307:    { \    DO_IF_RUN_UNLOCKED(mt_unlock(&PIKE_CONCAT(DATA,_mutex))); \    return 0; \    } \    hval%=PIKE_CONCAT(DATA,_hash_table_size); \    if((p=PIKE_CONCAT3(really_low_find_,DATA,_unlocked)(ptr, hval))) \    { \    PIKE_CONCAT(num_,DATA)--; \    if(PIKE_CONCAT(DATA,_hash_table)[hval]!=p) fatal("GAOssdf\n"); \    PIKE_CONCAT(DATA,_hash_table)[hval]=p->BLOCK_ALLOC_NEXT; \ -  PIKE_CONCAT3(really_free_,DATA,_unlocked)(p); \ +  BA_UL(PIKE_CONCAT(really_free_,DATA))(p); \    DO_IF_RUN_UNLOCKED(mt_unlock(&PIKE_CONCAT(DATA,_mutex))); \    return 1; \    } \    DO_IF_RUN_UNLOCKED(mt_unlock(&PIKE_CONCAT(DATA,_mutex))); \    return 0; \   } \    \   void PIKE_CONCAT3(init_,DATA,_hash)(void) \   { \    extern INT32 hashprimes[32]; \