pike.git / src / threads.c

version» Context lines:

pike.git/src/threads.c:1:   #include "global.h" - RCSID("$Id: threads.c,v 1.130 2000/06/24 00:48:13 hubbe Exp $"); + RCSID("$Id: threads.c,v 1.131 2000/06/24 07:20:27 hubbe Exp $");      int num_threads = 1;   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:187: Inside #if defined(SIMULATE_COND_WITH_EVENT)
   t=c->head;    mt_unlock(& c->lock);    if(t) return -1;    mt_destroy(& c->lock);    return 0;   }      #endif       - #define THIS_THREAD ((struct thread_state *)CURRENT_STORAGE) + #define THIS_THREAD ((struct Pike_interpreter *)CURRENT_STORAGE)      struct object *thread_id = NULL;   static struct callback *threads_evaluator_callback=0;   int thread_id_result_variable;      int th_running = 0;   #ifdef PIKE_DEBUG   int debug_interpreter_is_locked = 0;   THREAD_T debug_locking_thread;   #endif
pike.git/src/threads.c:378:    /* Just to be nice... */    mt_unlock(&(im->lock));       exit_threads_disable(NULL);   }      /* Thread hashtable */      #define THREAD_TABLE_SIZE 127 /* Totally arbitrary prime */    - static struct thread_state *thread_table_chains[THREAD_TABLE_SIZE]; + static struct Pike_interpreter *thread_table_chains[THREAD_TABLE_SIZE];   static int num_pike_threads=0;      void thread_table_init(void)   {    INT32 x;    for(x=0; x<THREAD_TABLE_SIZE; x++)    thread_table_chains[x] = NULL;   }      unsigned INT32 thread_table_hash(THREAD_T *tid)
pike.git/src/threads.c:408: Inside #if defined(PIKE_DEBUG)
   fprintf(stderr,"%s: ",desc);    for(e=0;e<size;e++)    fprintf(stderr,"%02x",tmp[e]);    fprintf(stderr,"\n");   }   #endif         void thread_table_insert(struct object *o)   { -  struct thread_state *s = OBJ2THREAD(o); +  struct Pike_interpreter *s = OBJ2THREAD(o);    unsigned INT32 h = thread_table_hash(&s->id);   #ifdef PIKE_DEBUG    if(h>=THREAD_TABLE_SIZE)    fatal("thread_table_hash failed miserably!\n");    if(thread_state_for_id(s->id))    {    if(thread_state_for_id(s->id) == s)    fatal("Registring thread twice!\n");    else    fatal("Forgot to unregister thread!\n");
pike.git/src/threads.c:433:    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 );   }      void thread_table_delete(struct object *o)   { -  struct thread_state *s = OBJ2THREAD(o); +  struct Pike_interpreter *s = OBJ2THREAD(o);   /* 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 );   }    - struct thread_state *thread_state_for_id(THREAD_T tid) + struct Pike_interpreter *thread_state_for_id(THREAD_T tid)   {    unsigned INT32 h = thread_table_hash(&tid); -  struct thread_state *s = NULL; +  struct Pike_interpreter *s = NULL;   #if 0    if(num_threads>1)    dumpmem("thread_state_for_id: ",&tid,sizeof(tid));   #endif   #ifdef PIKE_DEBUG    if(h>=THREAD_TABLE_SIZE)    fatal("thread_table_hash failed miserably!\n");   #endif    mt_lock( & thread_table_lock );    if(thread_table_chains[h] == NULL)
pike.git/src/threads.c:470:    else if(th_equal((s=thread_table_chains[h])->id, tid))    {    /* Quick return */    }    else    {    while((s = s->hashlink) != NULL)    if(th_equal(s->id, tid))    break;    if(s != NULL) { -  /* Move the thread_state to the head of the chain, in case +  /* Move the Pike_interpreter to the head of the chain, in case    we want to search for it again */       /* Unlink */    if(s->hashlink != NULL)    s->hashlink->backlink = s->backlink;    *(s->backlink) = s->hashlink;    /* And relink at the head of the chain */    if((s->hashlink = thread_table_chains[h]) != NULL)    s->hashlink->backlink = &s->hashlink;    thread_table_chains[h] = s;
pike.git/src/threads.c:496: Inside #if 0
   if(num_threads>1 && s)    dumpmem("thread_state_for_id return value: ",&s->id,sizeof(tid));   #endif    return s;    /* NOTEZ BIEN: Return value only guaranteed to remain valid as long    as you have the interpreter lock, unless tid == th_self() */   }      struct object *thread_for_id(THREAD_T tid)   { -  struct thread_state *s = thread_state_for_id(tid); +  struct Pike_interpreter *s = thread_state_for_id(tid);    return (s == NULL? NULL : THREADSTATE2OBJ(s));    /* See NB in thread_state_for_id. Lifespan of result can be prolonged    by incrementing refcount though. */   }         void f_all_threads(INT32 args)   {    /* Return an unordered array containing all threads that was running    at the time this function was invoked */       INT32 x;    struct svalue *oldsp; -  struct thread_state *s; +  struct Pike_interpreter *s;       pop_n_elems(args);    oldsp = sp;    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 );
pike.git/src/threads.c:1012:    pop_n_elems(args);   }      void f_cond_signal(INT32 args) { pop_n_elems(args); co_signal(THIS_COND); }   void f_cond_broadcast(INT32 args) { pop_n_elems(args); co_broadcast(THIS_COND); }   void init_cond_obj(struct object *o) { co_init(THIS_COND); }   void exit_cond_obj(struct object *o) { co_destroy(THIS_COND); }      void f_thread_backtrace(INT32 args)   { -  struct thread_state *foo = THIS_THREAD; -  struct thread_state *bar = OBJ2THREAD( thread_id ); +  struct Pike_interpreter *foo = THIS_THREAD; +  struct Pike_interpreter *bar = OBJ2THREAD( thread_id );    struct svalue *osp = sp;    pop_n_elems(args);    if(foo->sp)    {    SWAP_OUT_THREAD(bar);    SWAP_IN_THREAD(foo);    sp=osp;    f_backtrace(0);    osp=sp;    sp=foo->sp;
pike.git/src/threads.c:1050:   {    pop_n_elems (args);    push_constant_text ("Thread.Thread(");    push_int (THIS_THREAD->id);    push_constant_text (")");    f_add (3);   }      static void f_thread_id_result(INT32 args)   { -  struct thread_state *th=THIS_THREAD; +  struct Pike_interpreter *th=THIS_THREAD;       SWAP_OUT_CURRENT_THREAD();       while(th->status != THREAD_EXITED)    co_wait_interpreter(&th->status_change);       SWAP_IN_CURRENT_THREAD();       low_object_index_no_free(sp,    fp->current_object,    thread_id_result_variable);    sp++;   }      void init_thread_obj(struct object *o)   { -  MEMSET(THIS_THREAD, 0, sizeof(struct thread_state)); +  MEMSET(THIS_THREAD, 0, sizeof(struct Pike_interpreter));    THIS_THREAD->status=THREAD_NOT_STARTED;    co_init(& THIS_THREAD->status_change);    THIS_THREAD->thread_local=NULL;   }         void exit_thread_obj(struct object *o)   {    if(THIS_THREAD->thread_local != NULL) {    free_mapping(THIS_THREAD->thread_local);    THIS_THREAD->thread_local = NULL;    }    co_destroy(& THIS_THREAD->status_change);    th_destroy(& THIS_THREAD->id);   }      static void thread_was_recursed(struct object *o)   { -  struct thread_state *tmp=THIS_THREAD; +  struct Pike_interpreter *tmp=THIS_THREAD;    if(tmp->thread_local != NULL)    gc_recurse_mapping(tmp->thread_local);   }      static void thread_was_checked(struct object *o)   { -  struct thread_state *tmp=THIS_THREAD; +  struct Pike_interpreter *tmp=THIS_THREAD;    if(tmp->thread_local != NULL)    debug_gc_check(tmp->thread_local, T_OBJECT, o);      #ifdef PIKE_DEBUG    if(tmp->swapped)    {    struct pike_frame *f;    debug_malloc_touch(o);    debug_gc_xmark_svalues(tmp->evaluator_stack,tmp->sp-tmp->evaluator_stack-1," in idle thread stack");   
pike.git/src/threads.c:1288:    add_ref(thread_local_prog);    end_class("thread_local", 0);    if(!thread_local_prog)    fatal("Failed to initialize thread_local program!\n");    /* function(:object(thread_local)) */    ADD_EFUN("thread_local",f_thread_local,    tFunc(tNone,tObjIs_THREAD_LOCAL),    OPT_SIDE_EFFECT);       START_NEW_PROGRAM_ID(THREAD_ID); -  thread_storage_offset=ADD_STORAGE(struct thread_state); +  thread_storage_offset=ADD_STORAGE(struct Pike_interpreter);    thread_id_result_variable=simple_add_variable("result","mixed",0);    /* function(:array) */    ADD_FUNCTION("backtrace",f_thread_backtrace,tFunc(tNone,tArray),0);    /* function(:mixed) */    ADD_FUNCTION("wait",f_thread_id_result,tFunc(tNone,tMix),0);    /* function(:int) */    ADD_FUNCTION("status",f_thread_id_status,tFunc(tNone,tInt),0);    ADD_FUNCTION("_sprintf",f_thread_id__sprintf,tFunc(tNone,tStr),0);    set_gc_recurse_callback(thread_was_recursed);    set_gc_check_callback(thread_was_checked);