pike.git / src / threads.c

version» Context lines:

pike.git/src/threads.c:1:   #include "global.h" +  + int num_threads = 1; + int threads_disabled = 0; +  + #ifdef _REENTRANT   #include "threads.h"   #include "array.h"   #include "object.h"   #include "macros.h" -  + #include "callback.h"    - int num_threads = 1; - int threads_disabled = 0; +    struct object *thread_id; -  + static struct callback *threads_evaluator_callback=0;    - #ifdef _REENTRANT -  +    MUTEX_T interpreter_lock = PTHREAD_MUTEX_INITIALIZER;   struct program *mutex_key = 0;   struct program *thread_id_prog = 0;   pthread_attr_t pattr;      struct thread_starter   {    struct object *id;    struct array *args;   };    -  + static void check_threads(struct callback *cb, void *arg) + { +  THREADS_ALLOW(); +  +  /* Allow other threads to run */ +  +  THREADS_DISALLOW(); + } +    void *new_thread_func(void * data)   {    struct thread_starter arg = *(struct thread_starter *)data;    JMP_BUF back;    INT32 tmp;       free((char *)data);       if(tmp=mt_lock( & interpreter_lock))    fatal("Failed to lock interpreter, errno %d\n",tmp);
pike.git/src/threads.c:54: Inside #if defined(_REENTRANT)
      UNSETJMP(back);       destruct(thread_id);       free_object(thread_id);    thread_id=0;       cleanup_interpret();    num_threads--; +  if(!num_threads) +  { +  remove_callback(threads_evaluator_callback); +  threads_evaluator_callback=0; +  }    mt_unlock(& interpreter_lock);    th_exit(0);   }         void f_thread_create(INT32 args)   {    pthread_t dummy;    struct thread_starter *arg;    int tmp;    arg=ALLOC_STRUCT(thread_starter);    arg->args=aggregate_array(args);    arg->id=clone(thread_id_prog,0);    tmp=th_create(&dummy,new_thread_func,arg);    if(!tmp)    {    num_threads++; -  +  +  if(num_threads == 1 && !threads_evaluator_callback) +  { +  threads_evaluator_callback=add_to_callback(&evaluator_callbacks, +  check_threads, 0,0); +  } +     push_object(arg->id);    arg->id->refs++;    } else {    free_object(arg->id);    free_array(arg->args);    free((char *)arg);    push_int(0);    }   }