pike.git / src / threads.c

version» Context lines:

pike.git/src/threads.c:1:   #include "global.h" - RCSID("$Id: threads.c,v 1.49 1998/01/02 08:18:43 hubbe Exp $"); + RCSID("$Id: threads.c,v 1.50 1998/01/03 07:12:12 hubbe 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"   #include "gc.h"    -  + #ifdef SIMULATE_COND_WITH_EVENT + int co_wait(COND_T *c, MUTEX_T *m) + { +  struct cond_t_queue me; +  event_init(&me.event); +  mt_lock(& c->lock); +  +  me.next=c->tail; +  c->tail=&me; +  if(!c->head) c->head=&me; +  +  mt_unlock(& c->lock); +  mt_unlock(m); +  event_wait(&me.event); +  mt_lock(m); +  +  event_destroy(& me.event); +  /* Cancellation point?? */ +  +  return 0; + } +  + int co_signal(COND_T *c) + { +  struct cond_t_queue *t; +  mt_lock(& c->lock); +  if(t=c->head) +  { +  c->head=t->next; +  t->next=0; +  if(!c->head) c->tail=0; +  } +  mt_unlock(& c->lock); +  if(t) +  event_signal(& t->event); +  return 0; + } +  + int co_broadcast(COND_T *c) + { +  struct cond_t_queue *t,*n; +  mt_lock(& c->lock); +  n=c->head; +  c->head=c->tail=0; +  mt_unlock(& c->lock); +  +  while((t=n)) +  { +  n=t->next; +  event_signal(& t->event); +  } +  +  return 0; + } +  + int co_destroy(COND_T *c) + { +  struct cond_t_queue *t; +  mt_lock(& c->lock); +  n=c->head; +  c->head=c->tail=0; +  if(t) return EBUSY; +  return 0; + } +  + #endif +  +    #define THIS_THREAD ((struct thread_state *)fp->current_storage)      struct object *thread_id;   static struct callback *threads_evaluator_callback=0;   int thread_id_result_variable;      MUTEX_T interpreter_lock;   struct program *mutex_key = 0;   struct program *thread_id_prog = 0;   #ifdef POSIX_THREADS