pike.git / src / block_alloc.h

version» Context lines:

pike.git/src/block_alloc.h:1:   /*   || This file is part of Pike. For copyright information see COPYRIGHT.   || Pike is distributed under GPL, LGPL and MPL. See the file COPYING   || for more information. - || $Id: block_alloc.h,v 1.59 2003/01/08 09:22:51 grubba Exp $ + || $Id: block_alloc.h,v 1.60 2003/02/24 15:17:40 grubba Exp $   */      #undef PRE_INIT_BLOCK   #undef INIT_BLOCK   #undef EXIT_BLOCK   #undef BLOCK_ALLOC   #undef LOW_PTR_HASH_ALLOC   #undef PTR_HASH_ALLOC_FIXED   #undef PTR_HASH_ALLOC   #undef COUNT_BLOCK
pike.git/src/block_alloc.h:26:   #define EXIT_BLOCK(X)   #define COUNT_BLOCK(X)   #define COUNT_OTHER()   #define BLOCK_ALLOC_HSIZE_SHIFT 2   #define MAX_EMPTY_BLOCKS 4      #ifndef BLOCK_ALLOC_USED   #define BLOCK_ALLOC_USED DO_IF_DMALLOC(real_used) DO_IF_NOT_DMALLOC(used)   #endif    + #ifndef PIKE_HASH_T + /* Used to be size_t, but that led to performance problems +  * on 64-bit architectures without % on 64bit unsigned. +  */ + #define PIKE_HASH_T unsigned INT32 + #endif /* !PIKE_HASH_T */ +    #ifdef PIKE_RUN_UNLOCKED   #include "threads.h"      /* Block Alloc UnLocked */   #define BA_UL(X) PIKE_CONCAT(X,_unlocked)   #define BA_STATIC static   #define BA_INLINE inline   #else   #define BA_UL(X) X   #define BA_STATIC
pike.git/src/block_alloc.h:340:   #define LOW_PTR_HASH_ALLOC(DATA,BSIZE) \    \   BLOCK_ALLOC(DATA,BSIZE) \    \   struct DATA **PIKE_CONCAT(DATA,_hash_table)=0; \   size_t PIKE_CONCAT(DATA,_hash_table_size)=0; \   size_t PIKE_CONCAT(DATA,_hash_table_magnitude)=0; \   static size_t PIKE_CONCAT(num_,DATA)=0; \    \   static inline struct DATA * \ -  PIKE_CONCAT3(really_low_find_,DATA,_unlocked)(void *ptr, size_t hval) \ +  PIKE_CONCAT3(really_low_find_,DATA,_unlocked)(void *ptr, \ +  PIKE_HASH_T hval) \   { \    struct DATA *p,**pp; \    p=PIKE_CONCAT(DATA,_hash_table)[hval]; \    if(!p || p->PTR_HASH_ALLOC_DATA == ptr) \    { \    DO_IF_RUN_UNLOCKED(mt_unlock(&PIKE_CONCAT(DATA,_mutex))); \    return p; \    } \    while((p=*(pp=&p->BLOCK_ALLOC_NEXT))) \    { \
pike.git/src/block_alloc.h:365:    PIKE_CONCAT(DATA,_hash_table)[hval]=p; \    return p; \    } \    } \    return 0; \   } \    \   struct DATA *PIKE_CONCAT(find_,DATA)(void *ptr) \   { \    struct DATA *p; \ -  size_t hval = (size_t)(((char *)ptr)-(char *)0); \ +  PIKE_HASH_T hval = (PIKE_HASH_T)(((char *)ptr)-(char *)0); \    DO_IF_RUN_UNLOCKED(mt_lock(&PIKE_CONCAT(DATA,_mutex))); \    if(!PIKE_CONCAT(DATA,_hash_table_size)) { \    DO_IF_RUN_UNLOCKED(mt_unlock(&PIKE_CONCAT(DATA,_mutex))); \    return 0; \    } \ -  hval%=PIKE_CONCAT(DATA,_hash_table_size); \ +  hval %= (PIKE_HASH_T)PIKE_CONCAT(DATA,_hash_table_size); \    p=PIKE_CONCAT3(really_low_find_,DATA,_unlocked)(ptr, hval); \    DO_IF_RUN_UNLOCKED(mt_unlock(&PIKE_CONCAT(DATA,_mutex))); \    return p; \   } \    \    \    \   struct DATA *PIKE_CONCAT(make_,DATA)(void *ptr) \   { \    struct DATA *p; \ -  size_t hval=(size_t)(((char *)ptr)-(char *)0); \ +  PIKE_HASH_T hval = (PIKE_HASH_T)(((char *)ptr)-(char *)0); \    DO_IF_RUN_UNLOCKED(mt_lock(&PIKE_CONCAT(DATA,_mutex))); \ -  hval%=PIKE_CONCAT(DATA,_hash_table_size); \ +  hval %= (PIKE_HASH_T)PIKE_CONCAT(DATA,_hash_table_size); \    p=PIKE_CONCAT3(make_,DATA,_unlocked)(ptr,hval); \    DO_IF_RUN_UNLOCKED(mt_unlock(&PIKE_CONCAT(DATA,_mutex))); \    return p; \   } \    \   struct DATA *PIKE_CONCAT(get_,DATA)(void *ptr) \   { \    struct DATA *p; \ -  size_t hval=(size_t)(((char *)ptr)-(char *)0); \ +  PIKE_HASH_T hval = (size_t)(((char *)ptr)-(char *)0); \    DO_IF_RUN_UNLOCKED(mt_lock(&PIKE_CONCAT(DATA,_mutex))); \ -  hval%=PIKE_CONCAT(DATA,_hash_table_size); \ +  hval %= (PIKE_HASH_T)PIKE_CONCAT(DATA,_hash_table_size); \    if(!(p=PIKE_CONCAT3(really_low_find_,DATA,_unlocked)(ptr, hval))) \    p=PIKE_CONCAT3(make_,DATA,_unlocked)(ptr, hval); \    DO_IF_RUN_UNLOCKED(mt_unlock(&PIKE_CONCAT(DATA,_mutex))); \    return p; \   } \    \   int PIKE_CONCAT3(check_,DATA,_semafore)(void *ptr) \   { \    struct DATA *p; \ -  size_t hval=(size_t)(((char *)ptr)-(char *)0); \ +  PIKE_HASH_T hval = (PIKE_HASH_T)(((char *)ptr)-(char *)0); \    DO_IF_RUN_UNLOCKED(mt_lock(&PIKE_CONCAT(DATA,_mutex))); \ -  hval%=PIKE_CONCAT(DATA,_hash_table_size); \ +  hval %= (PIKE_HASH_T)PIKE_CONCAT(DATA,_hash_table_size); \    if((p=PIKE_CONCAT3(really_low_find_,DATA,_unlocked)(ptr, hval))) \    { \    DO_IF_RUN_UNLOCKED(mt_unlock(&PIKE_CONCAT(DATA,_mutex))); \    return 0; \    } \    \    PIKE_CONCAT3(make_,DATA,_unlocked)(ptr, hval); \    DO_IF_RUN_UNLOCKED(mt_unlock(&PIKE_CONCAT(DATA,_mutex))); \    return 1; \   } \    \   void PIKE_CONCAT(move_,DATA)(struct DATA *block, void *new_ptr) \   { \ -  size_t hval = (size_t)(((char *)block->PTR_HASH_ALLOC_DATA)-(char *)0); \ +  PIKE_HASH_T hval = \ +  (PIKE_HASH_T)(((char *)block->PTR_HASH_ALLOC_DATA)-(char *)0); \    DO_IF_RUN_UNLOCKED(mt_lock(&PIKE_CONCAT(DATA,_mutex))); \ -  hval %= PIKE_CONCAT(DATA,_hash_table_size); \ +  hval %= (PIKE_HASH_T)PIKE_CONCAT(DATA,_hash_table_size); \    if (!PIKE_CONCAT3(really_low_find_,DATA,_unlocked)( \    block->PTR_HASH_ALLOC_DATA, hval)) \    Pike_fatal("The block to move wasn't found.\n"); \    DO_IF_DEBUG( \    if (PIKE_CONCAT(DATA,_hash_table)[hval] != block) \    Pike_fatal("Expected the block to be at the top of the hash chain.\n"); \    ); \    PIKE_CONCAT(DATA,_hash_table)[hval] = block->BLOCK_ALLOC_NEXT; \    block->PTR_HASH_ALLOC_DATA = new_ptr; \ -  hval = (size_t)(((char *)new_ptr)-(char *)0) % \ -  PIKE_CONCAT(DATA,_hash_table_size); \ +  hval = (PIKE_HASH_T)(((char *)new_ptr)-(char *)0) % \ +  (PIKE_HASH_T)PIKE_CONCAT(DATA,_hash_table_size); \    block->BLOCK_ALLOC_NEXT = PIKE_CONCAT(DATA,_hash_table)[hval]; \    PIKE_CONCAT(DATA,_hash_table)[hval] = block; \    DO_IF_RUN_UNLOCKED(mt_unlock(&PIKE_CONCAT(DATA,_mutex))); \   } \    \   int PIKE_CONCAT(remove_,DATA)(void *ptr) \   { \    struct DATA *p; \ -  size_t hval=(size_t)(((char *)ptr)-(char *)0); \ +  PIKE_HASH_T hval = (PIKE_HASH_T)(((char *)ptr)-(char *)0); \    DO_IF_RUN_UNLOCKED(mt_lock(&PIKE_CONCAT(DATA,_mutex))); \    if(!PIKE_CONCAT(DATA,_hash_table)) \    { \    DO_IF_RUN_UNLOCKED(mt_unlock(&PIKE_CONCAT(DATA,_mutex))); \    return 0; \    } \ -  hval%=PIKE_CONCAT(DATA,_hash_table_size); \ +  hval %= (PIKE_HASH_T)PIKE_CONCAT(DATA,_hash_table_size); \    if((p=PIKE_CONCAT3(really_low_find_,DATA,_unlocked)(ptr, hval))) \    { \    PIKE_CONCAT(num_,DATA)--; \    DO_IF_DEBUG( if(PIKE_CONCAT(DATA,_hash_table)[hval]!=p) \    Pike_fatal("GAOssdf\n"); ); \    PIKE_CONCAT(DATA,_hash_table)[hval]=p->BLOCK_ALLOC_NEXT; \    BA_UL(PIKE_CONCAT(really_free_,DATA))(p); \    DO_IF_RUN_UNLOCKED(mt_unlock(&PIKE_CONCAT(DATA,_mutex))); \    return 1; \    } \
pike.git/src/block_alloc.h:532:   #define PTR_HASH_ALLOC(DATA,BSIZE) \   struct DATA *PIKE_CONCAT3(make_,DATA,_unlocked)(void *ptr, size_t hval); \   LOW_PTR_HASH_ALLOC(DATA,BSIZE) \    \   static void PIKE_CONCAT(DATA,_rehash)() \   { \    /* Time to re-hash */ \    extern INT32 hashprimes[32]; \    struct DATA **old_hash; \    struct DATA *p; \ -  size_t hval; \ +  PIKE_HASH_T hval; \    size_t e; \    \    old_hash= PIKE_CONCAT(DATA,_hash_table); \    e=PIKE_CONCAT(DATA,_hash_table_size); \    \    PIKE_CONCAT(DATA,_hash_table_magnitude)++; \    PIKE_CONCAT(DATA,_hash_table_size)= \    hashprimes[PIKE_CONCAT(DATA,_hash_table_magnitude)]; \    if((PIKE_CONCAT(DATA,_hash_table)=(struct DATA **) \    malloc(PIKE_CONCAT(DATA,_hash_table_size)* \    sizeof(struct DATA *)))) \    { \    MEMSET(PIKE_CONCAT(DATA,_hash_table),0, \    sizeof(struct DATA *)*PIKE_CONCAT(DATA,_hash_table_size)); \    while(e-- > 0) \    { \    while((p=old_hash[e])) \    { \    old_hash[e]=p->BLOCK_ALLOC_NEXT; \ -  hval=(size_t)(((char *)p->PTR_HASH_ALLOC_DATA)-(char *)0); \ -  hval%=PIKE_CONCAT(DATA,_hash_table_size); \ +  hval = (PIKE_HASH_T)(((char *)p->PTR_HASH_ALLOC_DATA)-(char *)0); \ +  hval %= (PIKE_HASH_T)PIKE_CONCAT(DATA,_hash_table_size); \    p->BLOCK_ALLOC_NEXT=PIKE_CONCAT(DATA,_hash_table)[hval]; \    PIKE_CONCAT(DATA,_hash_table)[hval]=p; \    } \    } \    free((char *)old_hash); \    }else{ \    PIKE_CONCAT(DATA,_hash_table)=old_hash; \    PIKE_CONCAT(DATA,_hash_table_size)=e; \    } \   } \    \ - struct DATA *PIKE_CONCAT3(make_,DATA,_unlocked)(void *ptr, size_t hval) \ + struct DATA *PIKE_CONCAT3(make_,DATA,_unlocked)(void *ptr, \ +  PIKE_HASH_T hval) \   { \    struct DATA *p; \    \    DO_IF_DEBUG( if(!PIKE_CONCAT(DATA,_hash_table)) \    Pike_fatal("Hash table error!\n"); ) \    PIKE_CONCAT(num_,DATA)++; \    \    if(( PIKE_CONCAT(num_,DATA)>>BLOCK_ALLOC_HSIZE_SHIFT ) >= \    PIKE_CONCAT(DATA,_hash_table_size)) \    { \    PIKE_CONCAT(DATA,_rehash)(); \ -  hval=(size_t)(((char *)ptr)-(char *)0); \ -  hval%=PIKE_CONCAT(DATA,_hash_table_size); \ +  hval = (PIKE_HASH_T)(((char *)ptr)-(char *)0); \ +  hval %= (PIKE_HASH_T)PIKE_CONCAT(DATA,_hash_table_size); \    } \    \    p=BA_UL(PIKE_CONCAT(alloc_,DATA))(); \    p->PTR_HASH_ALLOC_DATA=ptr; \    p->BLOCK_ALLOC_NEXT=PIKE_CONCAT(DATA,_hash_table)[hval]; \    PIKE_CONCAT(DATA,_hash_table)[hval]=p; \    return p; \   }