pike.git / src / threads.c

version» Context lines:

pike.git/src/threads.c:1:   #include "global.h" - RCSID("$Id: threads.c,v 1.121 2000/04/19 13:57:36 mast Exp $"); + RCSID("$Id: threads.c,v 1.122 2000/04/19 16:03:31 mast 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:194:   #endif         #define THIS_THREAD ((struct thread_state *)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   MUTEX_T interpreter_lock, thread_table_lock, interleave_lock;   struct program *mutex_key = 0;   struct program *thread_id_prog = 0;   struct program *thread_local_prog = 0;   #ifdef POSIX_THREADS   pthread_attr_t pattr;   pthread_attr_t small_pattr;   #endif   int thread_storage_offset;   
pike.git/src/threads.c:285:   {    low_init_threads_disable();       if(live_threads) {    SWAP_OUT_CURRENT_THREAD();    while (live_threads) {    THREADS_FPRINTF(0,    (stderr,    "_disable_threads(): Waiting for %d threads to finish\n",    live_threads)); -  co_wait(&live_threads_change, &interpreter_lock); +  co_wait_interpreter(&live_threads_change);    }    SWAP_IN_CURRENT_THREAD();    }   }      void exit_threads_disable(struct object *o)   {    THREADS_FPRINTF(0, (stderr, "exit_threads_disable(): threads_disabled:%d\n",    threads_disabled));    if(threads_disabled) {
pike.git/src/threads.c:552:      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));    -  if((tmp=mt_lock( & interpreter_lock))) +  if((tmp=mt_lock_interpreter()))    fatal("Failed to lock interpreter, return value=%d, errno=%d\n",tmp,   #ifdef __NT__    GetLastError()   #else    errno   #endif    );    init_interpreter();    thread_id=arg.id;    stack_top=((char *)&data)+ (thread_stack_size-16384) * STACK_DIRECTION;
pike.git/src/threads.c:647:    )    thread_table_delete(thread_id);    free_object(thread_id);    thread_id=0;    num_threads--;    if(!num_threads && threads_evaluator_callback)    {    remove_callback(threads_evaluator_callback);    threads_evaluator_callback=0;    } -  mt_unlock(& interpreter_lock); +  mt_unlock_interpreter();    th_exit(0);    /* NOT_REACHED, but removes a warning */    return(NULL);   }      #ifdef UNIX_THREADS   int num_lwps = 1;   #endif      void f_thread_create(INT32 args)
pike.git/src/threads.c:796:    {    if(threads_disabled)    {    free_object(o);    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(& m->condition, & interpreter_lock); +  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()) != thread_id)    fatal("thread_for_id() (or thread_id) failed! %p != %p\n",thread_for_id(th_self()),thread_id) ; )       THREADS_FPRINTF(1, (stderr, "LOCK k:%08x, m:%08x(%08x), t:%08x\n",
pike.git/src/threads.c:962:    if(!mut)    error("Bad argument 1 to condition->wait()\n");       /* Unlock mutex */    mut->key=0;    OB2KEY(key)->mut=0;    co_signal(& mut->condition);       /* Wait and allow mutex operations */    SWAP_OUT_CURRENT_THREAD(); -  co_wait(c, &interpreter_lock); +  co_wait_interpreter(c);       /* Lock mutex */    while(mut->key) -  co_wait(& mut->condition, &interpreter_lock); +  co_wait_interpreter(& mut->condition);    mut->key=key;    OB2KEY(key)->mut=mut;       SWAP_IN_CURRENT_THREAD();    pop_n_elems(args);    return;    }    }       SWAP_OUT_CURRENT_THREAD(); -  co_wait(c, &interpreter_lock); +  co_wait_interpreter(c);    SWAP_IN_CURRENT_THREAD();       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); }   
pike.git/src/threads.c:1033:    f_add (3);   }      static void f_thread_id_result(INT32 args)   {    struct thread_state *th=THIS_THREAD;       SWAP_OUT_CURRENT_THREAD();       while(th->status != THREAD_EXITED) -  co_wait(&th->status_change, &interpreter_lock); +  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)
pike.git/src/threads.c:1159:       THREADS_FPRINTF(0, (stderr, "THREADS_DISALLOW() Initializing threads.\n"));      #ifdef POSIX_THREADS   #ifdef HAVE_PTHREAD_INIT    pthread_init();   #endif /* HAVE_PTHREAD_INIT */   #endif /* POSIX_THREADS */       mt_init( & interpreter_lock); -  mt_lock( & interpreter_lock); +  mt_lock_interpreter();    mt_init( & thread_table_lock);    mt_init( & interleave_lock);    co_init( & live_threads_change);    co_init( & threads_disabled_change);    thread_table_init();   #ifdef POSIX_THREADS    pthread_attr_init(&pattr);   #ifdef HAVE_PTHREAD_ATTR_SETSTACKSIZE    pthread_attr_setstacksize(&pattr, thread_stack_size);   #endif