pike.git / src / threads.c

version» Context lines:

pike.git/src/threads.c:1:   #include "global.h" - RCSID("$Id: threads.c,v 1.113 2000/03/24 01:24:52 hubbe Exp $"); + RCSID("$Id: threads.c,v 1.114 2000/03/24 22:24:28 grubba 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:917:    THIS_KEY->mut=0;    THIS_KEY->initialized=0;    co_signal(& mut->condition);    }   }      #define THIS_COND ((COND_T *)(CURRENT_STORAGE))   void f_cond_wait(INT32 args)   {    COND_T *c; -  struct object *key; +     -  if(args > 1) pop_n_elems(args - 1); +  if(threads_disabled) +  error("Cannot wait for conditions when threads are disabled!\n");    -  +  if(args > 1) { +  pop_n_elems(args - 1); +  args = 1; +  } +     c=THIS_COND;    -  if(args > 0) +  if((args > 0) && !((sp[-1].type == T_INT) && (!sp[-1].u.integer)))    { -  +  struct object *key;    struct mutex_storage *mut;       if(sp[-1].type != T_OBJECT)    error("Bad argument 1 to condition->wait()\n");       key=sp[-1].u.object;       if(key->prog != mutex_key)    error("Bad argument 1 to condition->wait()\n");    -  mut=OB2KEY(key)->mut; -  if(!mut) error("Bad argument 1 to condition->wait()\n"); +  if (OB2KEY(key)->initialized) {    -  if(threads_disabled) -  error("Cannot wait for conditions when threads are disabled!\n"); +  mut = OB2KEY(key)->mut; +  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);    -  if(OB2KEY(key)->initialized) -  { +     /* Lock mutex */ -  while(mut->key) co_wait(& mut->condition, &interpreter_lock); +  while(mut->key) +  co_wait(& mut->condition, &interpreter_lock);    mut->key=key;    OB2KEY(key)->mut=mut; -  } +     SWAP_IN_CURRENT_THREAD(); -  pop_stack(); -  } else { +  pop_n_elems(args); +  return; +  } +  } +     SWAP_OUT_CURRENT_THREAD();    co_wait(c, &interpreter_lock);    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); }      void f_thread_backtrace(INT32 args)   {    struct thread_state *foo = THIS_THREAD;    struct thread_state *bar = OBJ2THREAD( thread_id );