pike.git / src / threads.c

version» Context lines:

pike.git/src/threads.c:1:   #include "global.h" - RCSID("$Id: threads.c,v 1.179 2002/06/17 15:42:39 grubba Exp $"); + RCSID("$Id: threads.c,v 1.180 2002/08/15 14:49:26 marcus 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:111: Inside #if defined(SIMULATE_COND_WITH_EVENT)
   mt_unlock(& c->lock);    mt_unlock(m);    event_wait(&me.event);    mt_lock(m);       event_destroy(& me.event);    /* Cancellation point?? */      #ifdef PIKE_DEBUG    if(me.next) -  fatal("Wait on event return prematurely!!\n"); +  Pike_fatal("Wait on event return prematurely!!\n");   #endif       return 0;   }      PMOD_EXPORT int co_signal(COND_T *c)   {    struct cond_t_queue *t;    mt_lock(& c->lock);    if((t=c->head))
pike.git/src/threads.c:333:       THREADS_FPRINTF(0, (stderr, "_exit_threads_disable(): Wake up!\n"));    disallow_live_threads = 0;    co_broadcast(&threads_disabled_change);   #ifdef PIKE_DEBUG    threads_disabled_thread = 0;   #endif    }   #ifdef PIKE_DEBUG    } else { -  fatal("exit_threads_disable() called too many times!\n"); +  Pike_fatal("exit_threads_disable() called too many times!\n");   #endif /* PIKE_DEBUG */    }   }      void init_interleave_mutex(IMUTEX_T *im)   {    mt_init(&(im->lock));       THREADS_FPRINTF(0, (stderr,    "init_interleave_mutex(): init_threads_disable()\n"));
pike.git/src/threads.c:423:   }   #endif         PMOD_EXPORT void thread_table_insert(struct object *o)   {    struct thread_state *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"); +  Pike_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"); +  Pike_fatal("Registring thread twice!\n");    else -  fatal("Forgot to unregister thread!\n"); +  Pike_fatal("Forgot to unregister thread!\n");    }   /* 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 );
pike.git/src/threads.c:464:   PMOD_EXPORT struct thread_state *thread_state_for_id(THREAD_T tid)   {    unsigned INT32 h = thread_table_hash(&tid);    struct thread_state *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"); +  Pike_fatal("thread_table_hash failed miserably!\n");   #endif    mt_lock( & thread_table_lock );    if(thread_table_chains[h] == NULL)    {    /* NULL result */    }    else if(th_equal((s=thread_table_chains[h])->id, tid))    {    /* Quick return */    }
pike.git/src/threads.c:617:    last_ = gethrtime();   #else    static int div_;    if(div_++ & 255)    return;   #endif      #ifdef 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) ; +  Pike_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"); +  Pike_fatal("Hashlink is wrong!\n");   #endif       THREADS_ALLOW();    /* Allow other threads to run */    th_yield();    THREADS_DISALLOW();       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) ; +  Pike_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",
pike.git/src/threads.c:656: Inside #if defined(HAVE_BROKEN_LINUX_THREAD_EUID)
   /* Work-around for Linux's pthreads not propagating the    * effective uid & gid.    */    if (!geteuid()) {    setegid(arg.egid);    seteuid(arg.euid);    }   #endif /* HAVE_BROKEN_LINUX_THREAD_EUID */       if((tmp=mt_lock_interpreter())) -  fatal("Failed to lock interpreter, return value=%d, errno=%d\n",tmp, +  Pike_fatal("Failed to lock interpreter, return value=%d, errno=%d\n",tmp,   #ifdef __NT__    GetLastError()   #else    errno   #endif    );    SWAP_IN_THREAD(OBJ2THREAD(arg.id)); /* Init struct */    init_interpreter();    Pike_interpreter.thread_id=arg.id;   #ifdef PROFILING
pike.git/src/threads.c:680:    Pike_interpreter.recoveries = NULL;    SWAP_OUT_THREAD(OBJ2THREAD(Pike_interpreter.thread_id)); /* Init struct */    OBJ2THREAD(Pike_interpreter.thread_id)->swapped=0;      #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", +  Pike_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) {    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) ; +  Pike_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) ; +  Pike_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.git/src/threads.c:731:    /* 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) ; +  Pike_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);
pike.git/src/threads.c:952:    */   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) ; +  Pike_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)    {
pike.git/src/threads.c:997:    }       /* 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) {    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) ; +  Pike_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");    }    do
pike.git/src/threads.c:1022:    SWAP_IN_CURRENT_THREAD();    check_threads_etc();    }while(m->key);    }    m->key=o;    OB2KEY(o)->mut=m;       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) ; +  Pike_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);   }
pike.git/src/threads.c:1180:    (unsigned int)THIS_KEY,    (unsigned int)THIS_KEY->mut,    (unsigned int)Pike_interpreter.thread_id,    (unsigned int)THIS_KEY->owner));    if(THIS_KEY->mut)    {    struct mutex_storage *mut = THIS_KEY->mut;      #ifdef PIKE_DEBUG    if(mut->key != o) -  fatal("Mutex unlock from wrong key %p != %p!\n",THIS_KEY->mut->key,o); +  Pike_fatal("Mutex unlock from wrong key %p != %p!\n",THIS_KEY->mut->key,o);   #endif    mut->key=0;    if (THIS_KEY->owner) {    free_object(THIS_KEY->owner);    THIS_KEY->owner=0;    }    THIS_KEY->mut=0;    THIS_KEY->initialized=0;    co_signal(& mut->condition);    }
pike.git/src/threads.c:1639: Inside #if defined(HAVE_BROKEN_LINUX_THREAD_EUID)
   * effective uid & gid.    */    if (!geteuid()) {    setegid(me->egid);    seteuid(me->euid);    }   #endif /* HAVE_BROKEN_LINUX_THREAD_EUID */       do    { - /* if(farmers == me) fatal("Ouch!\n"); */ + /* if(farmers == me) Pike_fatal("Ouch!\n"); */   /* fprintf(stderr, "farm_begin %p\n",me ); */    me->harvest( me->field );   /* fprintf(stderr, "farm_end %p\n", me); */       me->harvest = 0;    mt_lock( &rosie );    if( ++_num_idle_farmers > 16 )    {    --_num_idle_farmers;    --_num_farmers;
pike.git/src/threads.c:1683:   {    return _num_farmers;   }      static struct farmer *new_farmer(void (*fun)(void *), void *args)   {    struct farmer *me = malloc(sizeof(struct farmer));       if (!me) {    /* Out of memory */ -  fatal("new_farmer(): Out of memory!\n"); +  Pike_fatal("new_farmer(): Out of memory!\n");    }       dmalloc_accept_leak(me);       _num_farmers++;    me->neighbour = 0;    me->field = args;    me->harvest = fun;    co_init( &me->harvest_moon );   
pike.git/src/threads.c:1705: Inside #if defined(HAVE_BROKEN_LINUX_THREAD_EUID)
   me->euid = geteuid();    me->egid = getegid();   #endif /* HAVE_BROKEN_LINUX_THREAD_EUID */       th_create_small(&me->me, farm, me);    return me;   }      PMOD_EXPORT void th_farm(void (*fun)(void *), void *here)   { -  if(!fun) fatal("The farmers don't known how to handle empty fields\n"); +  if(!fun) Pike_fatal("The farmers don't known how to handle empty fields\n");    mt_lock( &rosie );    if(farmers)    {    struct farmer *f = farmers;    farmers = f->neighbour;    f->field = here;    f->harvest = fun;    mt_unlock( &rosie );    co_signal( &f->harvest_moon );    return;
pike.git/src/threads.c:1791:    map_variable("_owner", "object", 0,    mutex_key_offset + OFFSETOF(key_storage, owner), T_OBJECT);    set_init_callback(init_mutex_key_obj);    set_exit_callback(exit_mutex_key_obj);    mutex_key=Pike_compiler->new_program;    add_ref(mutex_key);    end_class("mutex_key", 0);    mutex_key->flags|=PROGRAM_DESTRUCT_IMMEDIATE;   #ifdef PIKE_DEBUG    if(!mutex_key) -  fatal("Failed to initialize mutex_key program!\n"); +  Pike_fatal("Failed to initialize mutex_key program!\n");   #endif       START_NEW_PROGRAM_ID(THREAD_MUTEX);    ADD_STORAGE(struct mutex_storage);    /* function(int(0..2)|void:object(mutex_key)) */    ADD_FUNCTION("lock",f_mutex_lock,    tFunc(tOr(tInt02,tVoid),tObjIs_THREAD_MUTEX_KEY),0);    /* function(int(0..2)|void:object(mutex_key)) */    ADD_FUNCTION("trylock",f_mutex_trylock,    tFunc(tOr(tInt02,tVoid),tObjIs_THREAD_MUTEX_KEY),0);
pike.git/src/threads.c:1851:    ADD_FUNCTION("set",f_thread_local_set,tFunc(tSetvar(1,tMix),tVar(1)),0);    ADD_FUNCTION("create", f_thread_local_create,    tFunc(tVoid,tVoid), ID_STATIC);   #ifdef PIKE_DEBUG    set_gc_check_callback(gc_check_thread_local);   #endif    thread_local_prog=Pike_compiler->new_program;    add_ref(thread_local_prog);    end_class("thread_local", 0);    if(!thread_local_prog) -  fatal("Failed to initialize thread_local program!\n"); +  Pike_fatal("Failed to initialize thread_local program!\n");    ADD_EFUN("thread_local", f_thread_local,    tFunc(tNone,tObjIs_THREAD_LOCAL),    OPT_EXTERNAL_DEPEND);       START_NEW_PROGRAM_ID(THREAD_ID);    thread_storage_offset=ADD_STORAGE(struct thread_state);    thread_id_result_variable=simple_add_variable("result","mixed",0);    /* function(:array) */    ADD_FUNCTION("backtrace",f_thread_backtrace,tFunc(tNone,tArray),0);    /* function(:mixed) */
pike.git/src/threads.c:1897:    ADD_EFUN("all_threads",f_all_threads,    tFunc(tNone,tArr(tObjIs_THREAD_ID)),    OPT_EXTERNAL_DEPEND);       /* Some constants... */    add_integer_constant("THREAD_NOT_STARTED", THREAD_NOT_STARTED, 0);    add_integer_constant("THREAD_RUNNING", THREAD_RUNNING, 0);    add_integer_constant("THREAD_EXITED", THREAD_EXITED, 0);       if(!mutex_key) -  fatal("Failed to initialize thread program!\n"); +  Pike_fatal("Failed to initialize thread program!\n");       Pike_interpreter.thread_id=clone_object(thread_id_prog,0);    SWAP_OUT_THREAD(OBJ2THREAD(Pike_interpreter.thread_id)); /* Init struct */    OBJ2THREAD(Pike_interpreter.thread_id)->id=th_self();    OBJ2THREAD(Pike_interpreter.thread_id)->swapped=0;    thread_table_insert(Pike_interpreter.thread_id);   }      void th_cleanup(void)   {