Branch: Tag:

2001-03-28

2001-03-28 10:02:45 by Fredrik Hübinette (Hubbe) <hubbe@hubbe.net>

lots of PIKE_RUN_UNLOCKED stuff..

Rev: src/Makefile.in:1.253
Rev: src/backend.cmod:1.13
Rev: src/block_alloc.h:1.28
Rev: src/error.c:1.71
Rev: src/gc.c:1.148
Rev: src/global.h:1.60
Rev: src/main.c:1.119
Rev: src/mapping.c:1.119
Rev: src/modules/Image/encodings/xbm.c:1.14
Rev: src/modules/Parser/html.c:1.132
Rev: src/modules/spider/xml.c:1.39
Rev: src/pike_cpulib.c:1.1
Rev: src/pike_cpulib.h:1.6
Rev: src/pike_error.h:1.11
Rev: src/pike_memory.c:1.103
Rev: src/program.c:1.306
Rev: src/stralloc.c:1.118
Rev: src/svalue.h:1.84

1: - /* $Id: block_alloc.h,v 1.27 2000/12/05 21:08:15 per Exp $ */ + /* $Id: block_alloc.h,v 1.28 2001/03/28 10:02:40 hubbe Exp $ */   #undef PRE_INIT_BLOCK   #undef INIT_BLOCK   #undef EXIT_BLOCK
13:   #define COUNT_BLOCK(X)   #define COUNT_OTHER()    + #ifdef PIKE_RUN_UNLOCKED + #include "threads.h" + #endif +  +    #define BLOCK_ALLOC(DATA,BSIZE) \    \   struct PIKE_CONCAT(DATA,_block) \
22:   }; \    \   static struct PIKE_CONCAT(DATA,_block) *PIKE_CONCAT(DATA,_blocks)=0; \ - static struct DATA *PIKE_CONCAT3(free_,DATA,s)=0; \ + static struct DATA *PIKE_CONCAT3(free_,DATA,s)=(struct DATA *)-1; \ + DO_IF_RUN_UNLOCKED(static PIKE_MUTEX_T PIKE_CONCAT(DATA,_mutex);) \    \   struct DATA *PIKE_CONCAT(alloc_,DATA)(void) \   { \    struct DATA *tmp; \ -  +  DO_IF_RUN_UNLOCKED(mt_lock(&PIKE_CONCAT(DATA,_mutex))); \    if(!PIKE_CONCAT3(free_,DATA,s)) \    { \    struct PIKE_CONCAT(DATA,_block) *n; \
53:    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); \ +  DO_IF_RUN_UNLOCKED(mt_unlock(&PIKE_CONCAT(DATA,_mutex))); \    return tmp; \   } \    \   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))); \   } \    \   void PIKE_CONCAT3(free_all_,DATA,_blocks)(void) \   { \    struct PIKE_CONCAT(DATA,_block) *tmp; \ -  +  DO_IF_RUN_UNLOCKED(mt_lock(&PIKE_CONCAT(DATA,_mutex))); \    DO_IF_DMALLOC( \    for(tmp=PIKE_CONCAT(DATA,_blocks);tmp;tmp=tmp->next) \    { \
84:    } \    PIKE_CONCAT(DATA,_blocks)=0; \    PIKE_CONCAT3(free_,DATA,s)=0; \ +  DO_IF_RUN_UNLOCKED(mt_unlock(&PIKE_CONCAT(DATA,_mutex))); \   } \    \    \
92:    INT32 num=0, size=0; \    struct PIKE_CONCAT(DATA,_block) *tmp; \    struct DATA *tmp2; \ +  DO_IF_RUN_UNLOCKED(mt_lock(&PIKE_CONCAT(DATA,_mutex))); \    for(tmp=PIKE_CONCAT(DATA,_blocks);tmp;tmp=tmp->next) \    { \    num+=BSIZE; \
103:    COUNT_OTHER(); \    *num_=num; \    *size_=size; \ - } +  DO_IF_RUN_UNLOCKED(mt_unlock(&PIKE_CONCAT(DATA,_mutex))); \ + } \ +  \ +  \ + void PIKE_CONCAT3(init_,DATA,_blocks)(void) \ + { \ +  DO_IF_RUN_UNLOCKED(mt_init_recursive(&PIKE_CONCAT(DATA,_mutex))); \ +  PIKE_CONCAT3(free_,DATA,s)=0; \ + } \          -  +    #define PTR_HASH_ALLOC(DATA,BSIZE) \    \   BLOCK_ALLOC(DATA,BSIZE) \
120:    PIKE_CONCAT(really_low_find_,DATA)(void *ptr, ptrdiff_t hval) \   { \    struct DATA *p,**pp; \ +  DO_IF_RUN_UNLOCKED(mt_lock(&PIKE_CONCAT(DATA,_mutex))); \    p=PIKE_CONCAT(DATA,_hash_table)[hval]; \ -  if(!p) return 0; \ -  if(p->data == ptr) return p; \ +  if(!p || p->data == ptr) \ +  { \ +  DO_IF_RUN_UNLOCKED(mt_unlock(&PIKE_CONCAT(DATA,_mutex))); \ +  return p; \ +  } \    while((p=*(pp=&p->BLOCK_ALLOC_NEXT))) \    { \    if(p->data==ptr) \
130:    *pp=p->BLOCK_ALLOC_NEXT; \    p->BLOCK_ALLOC_NEXT=PIKE_CONCAT(DATA,_hash_table)[hval]; \    PIKE_CONCAT(DATA,_hash_table)[hval]=p; \ +  DO_IF_RUN_UNLOCKED(mt_unlock(&PIKE_CONCAT(DATA,_mutex))); \    return p; \    } \    } \ -  +  DO_IF_RUN_UNLOCKED(mt_unlock(&PIKE_CONCAT(DATA,_mutex))); \    return 0; \   } \    \
149:   static void PIKE_CONCAT(DATA,_rehash)() \   { \    /* Time to re-hash */ \ -  struct DATA **old_hash= PIKE_CONCAT(DATA,_hash_table); \ +  struct DATA **old_hash; \    struct DATA *p; \    ptrdiff_t hval; \ -  ptrdiff_t e=PIKE_CONCAT(DATA,_hash_table_size); \ +  ptrdiff_t e; \    \ -  +  old_hash= PIKE_CONCAT(DATA,_hash_table); \ +  e=PIKE_CONCAT(DATA,_hash_table_size); \ +  \    PIKE_CONCAT(DATA,_hash_table_size)*=2; \    PIKE_CONCAT(DATA,_hash_table_size)++; \    if((PIKE_CONCAT(DATA,_hash_table)=(struct DATA **) \
185:   { \    struct DATA *p; \    \ +  DO_IF_RUN_UNLOCKED(mt_lock(&PIKE_CONCAT(DATA,_mutex))); \ +  \    DO_IF_DEBUG( if(!PIKE_CONCAT(DATA,_hash_table)) \    fatal("Hash table error!\n"); ) \    PIKE_CONCAT(num_,DATA)++; \
201:    p->data=ptr; \    p->BLOCK_ALLOC_NEXT=PIKE_CONCAT(DATA,_hash_table)[hval]; \    PIKE_CONCAT(DATA,_hash_table)[hval]=p; \ +  DO_IF_RUN_UNLOCKED(mt_unlock(&PIKE_CONCAT(DATA,_mutex))); \    return p; \   } \    \
208:   { \    struct DATA *p; \    ptrdiff_t hval=(ptrdiff_t)ptr; \ +  DO_IF_RUN_UNLOCKED(mt_lock(&PIKE_CONCAT(DATA,_mutex))); \    hval%=PIKE_CONCAT(DATA,_hash_table_size); \ -  if((p=PIKE_CONCAT(really_low_find_,DATA)(ptr, hval))) \ -  return p; \ -  \ -  return PIKE_CONCAT(make_,DATA)(ptr, hval); \ +  if(!(p=PIKE_CONCAT(really_low_find_,DATA)(ptr, hval))) \ +  p=PIKE_CONCAT(make_,DATA)(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; \    ptrdiff_t hval=(ptrdiff_t)ptr; \ -  +  DO_IF_RUN_UNLOCKED(mt_lock(&PIKE_CONCAT(DATA,_mutex))); \    hval%=PIKE_CONCAT(DATA,_hash_table_size); \    if((p=PIKE_CONCAT(really_low_find_,DATA)(ptr, hval))) \ -  +  { \ +  DO_IF_RUN_UNLOCKED(mt_unlock(&PIKE_CONCAT(DATA,_mutex))); \    return 0; \ -  +  } \    \    PIKE_CONCAT(make_,DATA)(ptr, hval); \ -  +  DO_IF_RUN_UNLOCKED(mt_unlock(&PIKE_CONCAT(DATA,_mutex))); \    return 1; \   } \    \
231:   { \    struct DATA *p; \    ptrdiff_t hval=(ptrdiff_t)ptr; \ -  if(!PIKE_CONCAT(DATA,_hash_table)) return 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); \    if((p=PIKE_CONCAT(really_low_find_,DATA)(ptr, hval))) \    { \
239:    if(PIKE_CONCAT(DATA,_hash_table)[hval]!=p) fatal("GAOssdf\n"); \    PIKE_CONCAT(DATA,_hash_table)[hval]=p->BLOCK_ALLOC_NEXT; \    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]; \ -  extern int my_log2(size_t x); \ +  extern int my_log2(size_t x); \ +  PIKE_CONCAT3(init_,DATA,_blocks)(); \ +  DO_IF_RUN_UNLOCKED(mt_lock(&PIKE_CONCAT(DATA,_mutex))); \    PIKE_CONCAT(DATA,_hash_table_size)=hashprimes[my_log2(BSIZE)]; \    \    PIKE_CONCAT(DATA,_hash_table)=(struct DATA **) \
259:    } \    MEMSET(PIKE_CONCAT(DATA,_hash_table),0, \    sizeof(struct DATA *)*PIKE_CONCAT(DATA,_hash_table_size)); \ +  DO_IF_RUN_UNLOCKED(mt_unlock(&PIKE_CONCAT(DATA,_mutex))); \   } \    \   void PIKE_CONCAT3(exit_,DATA,_hash)(void) \   { \ -  +  DO_IF_RUN_UNLOCKED(mt_lock(&PIKE_CONCAT(DATA,_mutex))); \    PIKE_CONCAT3(free_all_,DATA,_blocks)(); \    free(PIKE_CONCAT(DATA,_hash_table)); \    PIKE_CONCAT(DATA,_hash_table)=0; \    PIKE_CONCAT(num_,DATA)=0; \ -  +  DO_IF_RUN_UNLOCKED(mt_unlock(&PIKE_CONCAT(DATA,_mutex))); \   }