Branch: Tag:

2001-11-09

2001-11-09 02:09:14 by Fredrik Hübinette (Hubbe) <hubbe@hubbe.net>

Changes from Hubbe
speedups, optimizations, memory leak fixes and some bug fixes

Rev: src/pike_error.h:1.15
Rev: src/pike_threadlib.h:1.12
Rev: src/threads.c:1.174

1:   #include "global.h" - RCSID("$Id: threads.c,v 1.173 2001/11/02 14:05:14 mast Exp $"); + RCSID("$Id: threads.c,v 1.174 2001/11/09 02:09:14 nilsson Exp $");      PMOD_EXPORT int num_threads = 1;   PMOD_EXPORT int threads_disabled = 0;
410:   }      #ifdef PIKE_DEBUG - static void dumpmem(char *desc, void *x, int size) + void dumpmem(char *desc, void *x, int size)   {    int e;    unsigned char *tmp=(unsigned char *)x;
575:    f_aggregate(DO_NOT_WARN(Pike_sp - oldsp));   }    + #ifdef PIKE_DEBUG + void debug_list_all_threads(void) + { +  INT32 x; +  struct thread_state *s; +  THREAD_T self = th_self();    -  +  fprintf(stderr,"--Listing all threads--\n"); +  dumpmem("Current thread: ",&self, sizeof(self)); +  fprintf(stderr,"Current thread obj: %p\n",Pike_interpreter.thread_id); +  fprintf(stderr,"Current thread hash: %d\n",thread_table_hash(&self)); +  fprintf(stderr,"Current stack pointer: %p\n",&self); +  for(x=0; x<THREAD_TABLE_SIZE; x++) +  { +  for(s=thread_table_chains[x]; s; s=s->hashlink) { +  struct object *o = THREADSTATE2OBJ(s); +  fprintf(stderr,"ThTab[%d]: %p (stackbase=%p)",x,o,s->state.stack_top); +  dumpmem(" ",&s->id, sizeof(s->id)); +  } +  } +  fprintf(stderr,"-----------------------\n"); + } + #endif +    PMOD_EXPORT int count_pike_threads(void)   {    return num_pike_threads;
595:   #endif      #ifdef DEBUG -  if(thread_for_id(th_self()) != Pike_interpreter.thread_id) -  fatal("thread_for_id() (or Pike_interpreter.thread_id) failed!\n") +  if(thread_for_id(th_self()) != Pike_interpreter.thread_id) { +  debug_list_all_threads(); +  fatal("thread_for_id() (or Pike_interpreter.thread_id) failed! %p != %p\n",thread_for_id(th_self()),Pike_interpreter.thread_id) ; +  }       if(Pike_interpreter.backlink != OBJ2THREAD(Pike_interpreter.thread_id))    fatal("Hashlink is wrong!\n");
607:    th_yield();    THREADS_DISALLOW();    - #ifdef DEBUG -  if(thread_for_id(th_self()) != Pike_interpreter.thread_id) -  fatal("thread_for_id() (or Pike_interpreter.thread_id) failed!\n") - #endif +  DO_IF_DEBUG( +  if(thread_for_id(th_self()) != Pike_interpreter.thread_id) { +  debug_list_all_threads(); +  fatal("thread_for_id() (or Pike_interpreter.thread_id) failed! %p != %p\n",thread_for_id(th_self()),Pike_interpreter.thread_id) ; +  } )   }      TH_RETURN_TYPE new_thread_func(void * data)
660: Inside #if defined(PIKE_DEBUG)
   fatal("Current thread is wrong. %lx %lx\n",    (long)OBJ2THREAD(Pike_interpreter.thread_id)->id, (long)self);    -  if(thread_for_id(th_self()) != Pike_interpreter.thread_id) -  fatal("thread_for_id() (or Pike_interpreter.thread_id) failed in new_thread_func! " -  "%p != %p\n", thread_for_id(self), Pike_interpreter.thread_id); +  if(thread_for_id(th_self()) != Pike_interpreter.thread_id) { +  debug_list_all_threads(); +  fatal("thread_for_id() (or Pike_interpreter.thread_id) failed! %p != %p\n",thread_for_id(th_self()),Pike_interpreter.thread_id) ;    } -  +  }   #endif      #ifdef THREAD_TRACE
673:   #endif /* THREAD_TRACE */       THREADS_FPRINTF(0, (stderr,"THREAD %08x INITED\n",(unsigned int)Pike_interpreter.thread_id)); +  +  DO_IF_DEBUG( +  if(thread_for_id(th_self()) != Pike_interpreter.thread_id) { +  debug_list_all_threads(); +  fatal("thread_for_id() (or Pike_interpreter.thread_id) failed! %p != %p\n",thread_for_id(th_self()),Pike_interpreter.thread_id) ; +  } ) +  +     if(SETJMP(back))    {    if(throw_severity < THROW_EXIT)
696:    pop_stack();    }    +  DO_IF_DEBUG( +  if(thread_for_id(th_self()) != Pike_interpreter.thread_id) { +  debug_list_all_threads(); +  fatal("thread_for_id() (or Pike_interpreter.thread_id) failed! %p != %p\n",thread_for_id(th_self()),Pike_interpreter.thread_id) ; +  } ) +  +     if(OBJ2THREAD(Pike_interpreter.thread_id)->thread_local != NULL) {    free_mapping(OBJ2THREAD(Pike_interpreter.thread_id)->thread_local);    OBJ2THREAD(Pike_interpreter.thread_id)->thread_local = NULL;
908:    struct object *o;    INT_TYPE type;    +  DO_IF_DEBUG( +  if(thread_for_id(th_self()) != Pike_interpreter.thread_id) { +  debug_list_all_threads(); +  fatal("thread_for_id() (or Pike_interpreter.thread_id) failed! %p != %p\n",thread_for_id(th_self()),Pike_interpreter.thread_id) ; +  } ) +     m=THIS_MUTEX;    if(!args)    type=0;
947:    */    o=fast_clone_object(mutex_key,0);    -  DO_IF_DEBUG( if(thread_for_id(th_self()) != Pike_interpreter.thread_id) -  fatal("thread_for_id() (or Pike_interpreter.thread_id) failed! %p != %p\n",thread_for_id(th_self()),Pike_interpreter.thread_id) ; ) +  DO_IF_DEBUG( +  if(thread_for_id(th_self()) != Pike_interpreter.thread_id) { +  debug_list_all_threads(); +  fatal("thread_for_id() (or Pike_interpreter.thread_id) failed! %p != %p\n",thread_for_id(th_self()),Pike_interpreter.thread_id) ; +  } )       if(m->key)    {
968:    m->key=o;    OB2KEY(o)->mut=m;    -  DO_IF_DEBUG( if(thread_for_id(th_self()) != Pike_interpreter.thread_id) -  fatal("thread_for_id() (or Pike_interpreter.thread_id) failed! %p != %p\n",thread_for_id(th_self()),Pike_interpreter.thread_id) ; ) +  DO_IF_DEBUG( +  if(thread_for_id(th_self()) != Pike_interpreter.thread_id) { +  debug_list_all_threads(); +  fatal("thread_for_id() (or Pike_interpreter.thread_id) failed! %p != %p\n",thread_for_id(th_self()),Pike_interpreter.thread_id) ; +  } )       THREADS_FPRINTF(1, (stderr, "LOCK k:%08x, m:%08x(%08x), t:%08x\n",    (unsigned int)OB2KEY(o),