pike.git / src / threads.c

version» Context lines:

pike.git/src/threads.c:1:   #include "global.h" - RCSID("$Id: threads.c,v 1.29 1997/09/03 03:39:58 per Exp $"); + RCSID("$Id: threads.c,v 1.30 1997/09/03 04:58:17 per Exp $");      int num_threads = 1;   int threads_disabled = 0;      #ifdef _REENTRANT   #include "threads.h"   #include "array.h"   #include "object.h"   #include "pike_macros.h"   #include "callback.h"   #include "builtin_functions.h"   #include "constants.h"   #include "program.h"         struct object *thread_id;   static struct callback *threads_evaluator_callback=0;    - MUTEX_T interpreter_lock = PTHREAD_MUTEX_INITIALIZER; + MUTEX_T interpreter_lock /*= PTHREAD_MUTEX_INITIALIZER*/;   struct program *mutex_key = 0;   struct program *thread_id_prog = 0;   #ifdef POSIX_THREADS   pthread_attr_t pattr;   #endif      struct thread_starter   {    struct object *id;    struct array *args;
pike.git/src/threads.c:43:   void *new_thread_func(void * data)   {    struct thread_starter arg = *(struct thread_starter *)data;    JMP_BUF back;    INT32 tmp;       if((tmp=mt_lock( & interpreter_lock)))    fatal("Failed to lock interpreter, errno %d\n",tmp);    THREADS_FPRINTF((stderr,"THREADS_DISALLOW() Thread created...\n"));    init_interpreter(); -  +     thread_id=arg.id; -  +  SWAP_OUT_THREAD((struct thread_state *)thread_id->storage); /* Init struct */ +  ((struct thread_state *)thread_id->storage)->swapped=0;       if(SETJMP(back))    {    ONERROR tmp;    SET_ONERROR(tmp,exit_on_error,"Error in handle_error in master object!");    assign_svalue_no_free(sp++, & throw_value);    APPLY_MASTER("handle_error", 1);    pop_stack();    UNSET_ONERROR(tmp);    } else {
pike.git/src/threads.c:161:    struct object *key;   };      struct key_storage   {    struct mutex_storage *mut;    struct object *owner;    int initialized;   };    - static MUTEX_T mutex_kluge = PTHREAD_MUTEX_INITIALIZER; + static MUTEX_T mutex_kluge/* = PTHREAD_MUTEX_INITIALIZER*/;      #define OB2KEY(X) ((struct key_storage *)((X)->storage))      void f_mutex_lock(INT32 args)   {    struct mutex_storage *m;    struct object *o;       pop_n_elems(args);    m=THIS_MUTEX;
pike.git/src/threads.c:354:    mt_unlock(&mutex_kluge);    THREADS_DISALLOW();    }   }      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 = (struct thread_state *)fp->current_object->storage; +  struct thread_state *bar = (struct thread_state *)thread_id->storage; +  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; +  SWAP_OUT_THREAD(foo); +  SWAP_IN_THREAD(bar); +  sp=osp; +  } else { +  push_int(0); +  f_allocate(1); +  } + } +  + void init_thread_obj(struct object *o) + { +  MEMSET(o->storage, 0, sizeof(struct thread_state)); + } +    void th_init(void)   {    struct program *tmp;    INT32 mutex_key_offset;      #ifdef SGI_SPROC_THREADS   #error /* Need to specify a filename */    us_cookie = usinit("");   #endif /* SGI_SPROC_THREADS */   
pike.git/src/threads.c:413:    start_new_program();    add_storage(sizeof(COND_T));    add_function("wait",f_cond_wait,"function(void|object:void)",0);    add_function("signal",f_cond_signal,"function(:void)",0);    add_function("broadcast",f_cond_broadcast,"function(:void)",0);    set_init_callback(init_cond_obj);    set_exit_callback(exit_cond_obj);    end_class("condition", 0);       start_new_program(); +  add_storage(sizeof(struct thread_state)); +  add_function("backtrace",f_thread_backtrace,"function(:array)",0); +  set_init_callback(init_thread_obj);    thread_id_prog=end_program();    if(!mutex_key)    fatal("Failed to initialize thread program!\n");       thread_id=clone_object(thread_id_prog,0);   }      void th_cleanup(void)   {    if(mutex_key)