pike.git / src / threads.c

version» Context lines:

pike.git/src/threads.c: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: threads.c,v 1.223 2003/10/19 13:47:42 mast Exp $ + || $Id: threads.c,v 1.224 2003/10/19 14:10:05 mast Exp $   */      #ifndef CONFIGURE_TEST   #include "global.h" - RCSID("$Id: threads.c,v 1.223 2003/10/19 13:47:42 mast Exp $"); + RCSID("$Id: threads.c,v 1.224 2003/10/19 14:10:05 mast Exp $");      PMOD_EXPORT int num_threads = 1;   PMOD_EXPORT int threads_disabled = 0;   #endif /* !CONFIGURE_TEST */      #ifdef _REENTRANT      #ifndef CONFIGURE_TEST      #include "threads.h"
pike.git/src/threads.c:492:   unsigned INT32 thread_table_hash(THREAD_T *tid)   {    return th_hash(*tid) % THREAD_TABLE_SIZE;   }      #ifdef PIKE_DEBUG   void dumpmem(const char *desc, void *x, int size)   {    int e;    unsigned char *tmp=(unsigned char *)x; -  fprintf(stderr,"%s: ",desc); +  fprintf(stderr, "%s0x", desc);    for(e=0;e<size;e++)    fprintf(stderr,"%02x",tmp[e]);    fprintf(stderr,"\n");   }   #endif         PMOD_EXPORT void thread_table_insert(struct thread_state *s)   {    unsigned INT32 h = thread_table_hash(&s->id);   #ifdef PIKE_DEBUG    if(h>=THREAD_TABLE_SIZE)    Pike_fatal("thread_table_hash failed miserably!\n");    if(thread_state_for_id(s->id))    {    if(thread_state_for_id(s->id) == s)    Pike_fatal("Registring thread twice!\n");    else    Pike_fatal("Forgot to unregister thread!\n");    } - /* dumpmem("thread_table_insert",&s->id, sizeof(THREAD_T)); */ + /* dumpmem("thread_table_insert: ",&s->id, sizeof(THREAD_T)); */   #endif    mt_lock( & thread_table_lock );    num_pike_threads++;    if((s->hashlink = thread_table_chains[h]) != NULL)    s->hashlink->backlink = &s->hashlink;    thread_table_chains[h] = s;    s->backlink = &thread_table_chains[h];    mt_unlock( & thread_table_lock );   }      PMOD_EXPORT void thread_table_delete(struct thread_state *s)   { - /* dumpmem("thread_table_delete",&s->id, sizeof(THREAD_T)); */ + /* dumpmem("thread_table_delete: ",&s->id, sizeof(THREAD_T)); */    mt_lock( & thread_table_lock );    num_pike_threads--;    if(s->hashlink != NULL)    s->hashlink->backlink = s->backlink;    *(s->backlink) = s->hashlink;    mt_unlock( & thread_table_lock );   }      PMOD_EXPORT struct thread_state *thread_state_for_id(THREAD_T tid)   {
pike.git/src/threads.c:658: Inside #if defined(PIKE_DEBUG)
     #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 interpreter thread state: %p\n",Pike_interpreter.thread_state); +  fprintf(stderr,"Current interpreter thread state: %p%s\n", +  Pike_interpreter.thread_state, +  Pike_interpreter.thread_state == (struct thread_state *) (ptrdiff_t) -1 ? +  " (swapped)" : "");    fprintf(stderr,"Current thread state according to thread_state_for_id(): %p\n",    thread_state_for_id (self));    fprintf(stderr,"Current thread obj: %p\n", -  Pike_interpreter.thread_state? -  Pike_interpreter.thread_state->thread_obj:NULL); +  (Pike_interpreter.thread_state && +  Pike_interpreter.thread_state != (struct thread_state *) (ptrdiff_t) -1) ? +  Pike_interpreter.thread_state->thread_obj : NULL);    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,"ThTab[%d]: state=%p, obj=%p, " +  "swapped=%d, sp=%p (%+d), fp=%p, stackbase=%p", +  x, s, o, s->swapped, +  s->state.stack_pointer, +  s->state.stack_pointer - s->state.evaluator_stack, +  s->state.frame_pointer, +  s->state.stack_top); +  dumpmem(", id=",&s->id, sizeof(s->id));    }    }    fprintf(stderr,"-----------------------\n");   }   #endif      PMOD_EXPORT int count_pike_threads(void)   {    return num_pike_threads;   }