pike.git / src / threads.c

version» Context lines:

pike.git/src/threads.c:1:   #include "global.h" - RCSID("$Id: threads.c,v 1.91 1999/03/21 21:34:29 grubba Exp $"); + RCSID("$Id: threads.c,v 1.92 1999/04/02 23:23:47 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"   #include "callback.h"   #include "builtin_functions.h"   #include "constants.h"   #include "program.h"   #include "gc.h"   #include "main.h" -  + #include "module_support.h"      int live_threads = 0;   COND_T live_threads_change;   COND_T threads_disabled_change;   size_t thread_stack_size=1024 * 1204;      #ifdef __NT__      #ifdef PIKE_DEBUG   static int IsValidHandle(HANDLE h)
pike.git/src/threads.c:610:    struct object *owner;    int initialized;   };      #define OB2KEY(X) ((struct key_storage *)((X)->storage))      void f_mutex_lock(INT32 args)   {    struct mutex_storage *m;    struct object *o; +  INT_TYPE type;       m=THIS_MUTEX; -  /* Needs to be cloned here, since create() -  * might use threads. -  */ -  o=clone_object(mutex_key,0); -  if(!args || IS_ZERO(sp-args)) +  if(!args) +  type=0; +  else +  get_all_args("mutex->lock",args,"%i",&type); +  +  switch(type)    { -  +  default: +  bad_arg_error("mutex->lock", sp-args, args, 2, "int(0..2)", sp+1-args, +  "Unknown mutex locking style: %d\n",type); +  +  +  case 0: +  case 2:    if(m->key && OB2KEY(m->key)->owner == thread_id)    {    THREADS_FPRINTF(0,    (stderr, "Recursive LOCK k:%08x, m:%08x(%08x), t:%08x\n",    (unsigned int)OB2KEY(m->key),    (unsigned int)m,    (unsigned int)OB2KEY(m->key)->mut,    (unsigned int) thread_id)); -  free_object(o); -  error("Recursive mutex locks!\n"); +  +  if(type==0) error("Recursive mutex locks!\n"); +  +  pop_n_elems(args); +  push_int(0);    } -  +  case 1: +  break;    }    -  +  /* Needs to be cloned here, since create() +  * might use threads. +  */ +  o=clone_object(mutex_key,0); +     if(m->key)    {    SWAP_OUT_CURRENT_THREAD();    do    {    THREADS_FPRINTF(1, (stderr,"WAITING TO LOCK m:%08x\n",(unsigned int)m));    co_wait(& m->condition, & interpreter_lock);    }while(m->key);    SWAP_IN_CURRENT_THREAD();    }
pike.git/src/threads.c:657:    (unsigned int)OB2KEY(m->key)->mut,    (unsigned int)thread_id));    pop_n_elems(args);    push_object(o);   }      void f_mutex_trylock(INT32 args)   {    struct mutex_storage *m;    struct object *o; +  int type;    int i=0;    -  o=clone_object(mutex_key,0); -  m=THIS_MUTEX; -  +     /* No reason to release the interpreter lock here    * since we aren't calling any functions that take time.    */    -  if(!args || IS_ZERO(sp-args)) +  m=THIS_MUTEX; +  +  if(!args) +  type=0; +  else +  get_all_args("mutex->lock",args,"%i",&type); +  +  switch(type)    { -  +  default: +  bad_arg_error("mutex->trylock", sp-args, args, 2, "int(0..2)", sp+1-args, +  "Unknown mutex locking style: %d\n",type); +  +  case 0:    if(m->key && OB2KEY(m->key)->owner == thread_id)    { -  free_object(o); +     error("Recursive mutex locks!\n");    } -  +  +  case 2: +  case 1: +  break;    }    -  +  o=clone_object(mutex_key,0); +     if(!m->key)    {    OB2KEY(o)->mut=m;    m->key=o;    i=1;    }       pop_n_elems(args);    if(i)    {
pike.git/src/threads.c:1000:   /* function(:array(object)) */    ADD_EFUN("all_threads",f_all_threads,tFunc(,tArr(tObj)),    OPT_EXTERNAL_DEPEND);         /* function(:object) */    ADD_EFUN("thread_local",f_thread_local,tFunc(,tObj),OPT_SIDE_EFFECT);       start_new_program();    ADD_STORAGE(struct mutex_storage); +  add_function("lock",f_mutex_lock,"function(int(0..2)|void:object)",0);    /* function(int|void:object) */ -  ADD_FUNCTION("lock",f_mutex_lock,tFunc(tOr(tInt,tVoid),tObj),0); -  /* function(int|void:object) */ +     ADD_FUNCTION("trylock",f_mutex_trylock,tFunc(tOr(tInt,tVoid),tObj),0);    set_init_callback(init_mutex_obj);    set_exit_callback(exit_mutex_obj);    end_class("mutex", 0);       start_new_program();    mutex_key_offset = ADD_STORAGE(struct key_storage);    /* This is needed to allow the gc to find the possible circular reference.    * It also allows a process to take over ownership of a key.    */