pike.git / src / threads.c

version» Context lines:

pike.git/src/threads.c: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;      #ifdef _REENTRANT   #include "threads.h"   #include "array.h"   #include "mapping.h"   #include "object.h"   #include "pike_macros.h"
pike.git/src/threads.c:403:    for(x=0; x<THREAD_TABLE_SIZE; x++)    thread_table_chains[x] = NULL;   }      unsigned INT32 thread_table_hash(THREAD_T *tid)   {    return th_hash(*tid) % THREAD_TABLE_SIZE;   }      #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;    fprintf(stderr,"%s: ",desc);    for(e=0;e<size;e++)    fprintf(stderr,"%02x",tmp[e]);    fprintf(stderr,"\n");   }   #endif   
pike.git/src/threads.c:568:    mt_lock( & thread_table_lock );    for(x=0; x<THREAD_TABLE_SIZE; x++)    for(s=thread_table_chains[x]; s; s=s->hashlink) {    struct object *o = THREADSTATE2OBJ(s);    ref_push_object(o);    }    mt_unlock( & thread_table_lock );    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;   }      static void check_threads(struct callback *cb, void *arg, void * arg2)   {   #ifdef HAVE_GETHRTIME    static long long last_;    if( gethrtime()-last_ < 50000000 ) /* 0.05s slice */    return;    last_ = gethrtime();   #else    static int div_;    if(div_++ & 255)    return;   #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");   #endif       THREADS_ALLOW();    /* Allow other threads to run */    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)   {    struct thread_starter arg = *(struct thread_starter *)data;    JMP_BUF back;    INT32 tmp;       THREADS_FPRINTF(0, (stderr,"THREADS_DISALLOW() Thread %08x created...\n",    (unsigned int)arg.id));
pike.git/src/threads.c:653: Inside #if defined(PIKE_DEBUG)
     #if defined(PIKE_DEBUG)    if(d_flag)    {    THREAD_T self = th_self();       if( Pike_interpreter.thread_id && !th_equal( OBJ2THREAD(Pike_interpreter.thread_id)->id, self) )    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    {    t_flag = default_t_flag;    }   #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)    call_handle_error();    if(throw_severity == THROW_EXIT)    {    free((char *) data);    pike_do_exit(throw_value.u.integer);    }    } else {
pike.git/src/threads.c:689:    arg.args=0;    f_call_function(args);       /* copy return value to the Pike_interpreter.thread_id here */    object_low_set_index(Pike_interpreter.thread_id,    thread_id_result_variable,    Pike_sp-1);    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;    }       OBJ2THREAD(Pike_interpreter.thread_id)->status=THREAD_EXITED;    co_broadcast(& OBJ2THREAD(Pike_interpreter.thread_id)->status_change);       free((char *)data); /* Moved by per, to avoid some bugs.... */    UNSETJMP(back);
pike.git/src/threads.c:901:    *!    *! @seealso    *! @[trylock()]    */   void f_mutex_lock(INT32 args)   {    struct mutex_storage *m;    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;    else    get_all_args("mutex->lock",args,"%i",&type);       switch(type)    {    default:    bad_arg_error("mutex->lock", Pike_sp-args, args, 2, "int(0..2)", Pike_sp+1-args,
pike.git/src/threads.c:940:    }    case 1:    break;    }       /* Needs to be cloned here, since create()    * might use threads.    */    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)    {    if(threads_disabled)    {    free_object(o);    Pike_error("Cannot wait for mutexes when threads are disabled!\n");    }    SWAP_OUT_CURRENT_THREAD();    do    {    THREADS_FPRINTF(1, (stderr,"WAITING TO LOCK m:%08x\n",(unsigned int)m));    co_wait_interpreter(& m->condition);    }while(m->key);    SWAP_IN_CURRENT_THREAD();    }    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),    (unsigned int)m,    (unsigned int)OB2KEY(m->key)->mut,    (unsigned int)Pike_interpreter.thread_id));    pop_n_elems(args);    push_object(o);   }