pike.git / src / threads.c

version» Context lines:

pike.git/src/threads.c:1:   /*   || This file is part of Pike. For copyright information see COPYRIGHT.   || Pike is distributed under GPL, LGPL and MPL. See the file COPYING   || for more information. - || $Id: threads.c,v 1.261 2008/08/05 20:43:25 mast Exp $ + || $Id: threads.c,v 1.262 2008/08/05 21:23:46 mast Exp $   */      #include "global.h"      PMOD_EXPORT int num_threads = 1;   PMOD_EXPORT int threads_disabled = 0;      /* #define PICKY_MUTEX */      #ifdef _REENTRANT
pike.git/src/threads.c:1904:    num_pending_interrupts++;    if (!thread_interrupt_callback) {    thread_interrupt_callback =    add_to_callback(&evaluator_callbacks, check_thread_interrupt, 0, 0);    }    /* FIXME: Actually interrupt the thread. */    }    push_int(0);   }    + static void low_thread_kill (struct thread_state *th) + { +  if (!(th->flags & THREAD_FLAG_SIGNAL_MASK)) { +  num_pending_interrupts++; +  if (!thread_interrupt_callback) { +  thread_interrupt_callback = +  add_to_callback(&evaluator_callbacks, check_thread_interrupt, 0, 0); +  } +  /* FIXME: Actually interrupt the thread. */ +  } +  th->flags |= THREAD_FLAG_TERM; + } +    /*! @decl void kill()    *!    *! Interrupt the thread, and terminate it.    *!    *! @note    *! Interrupts are asynchronous, and are currently not queued.    */   static void f_thread_id_kill(INT32 args)   {    pop_n_elems(args); -  -  if (!(THIS_THREAD->flags & THREAD_FLAG_SIGNAL_MASK)) { -  num_pending_interrupts++; -  if (!thread_interrupt_callback) { -  thread_interrupt_callback = -  add_to_callback(&evaluator_callbacks, check_thread_interrupt, 0, 0); -  } -  /* FIXME: Actually interrupt the thread. */ -  } -  THIS_THREAD->flags |= THREAD_FLAG_TERM; +  low_thread_kill (THIS_THREAD);    push_int(0);   }      void init_thread_obj(struct object *o)   {    MEMSET(&THIS_THREAD->state, 0, sizeof(struct Pike_interpreter));    THIS_THREAD->thread_obj = Pike_fp->current_object;    THIS_THREAD->swapped = 0;    THIS_THREAD->status=THREAD_NOT_STARTED;    THIS_THREAD->flags = 0;
pike.git/src/threads.c:2426:    add_integer_constant("THREAD_NOT_STARTED", THREAD_NOT_STARTED, 0);    add_integer_constant("THREAD_RUNNING", THREAD_RUNNING, 0);    add_integer_constant("THREAD_EXITED", THREAD_EXITED, 0);       backend_thread_obj = fast_clone_object(thread_id_prog);    INIT_THREAD_STATE((struct thread_state *)(backend_thread_obj->storage +    thread_storage_offset));    thread_table_insert(Pike_interpreter.thread_state);   }    + #ifdef DO_PIKE_CLEANUP + void cleanup_all_other_threads (void) + { +  int i, num_kills = num_pending_interrupts; +  time_t timeout = time (NULL) + 2; +  +  mt_lock (&thread_table_lock); +  for (i = 0; i < THREAD_TABLE_SIZE; i++) { +  struct thread_state *th; +  for (th = thread_table_chains[i]; th; th = th->hashlink) +  if (th != Pike_interpreter.thread_state) { +  low_thread_kill (th); +  num_kills++; +  } +  } +  mt_unlock (&thread_table_lock); +  +  while (num_pending_interrupts && time (NULL) < timeout) { +  THREADS_ALLOW(); + #ifdef __NT__ +  Sleep (1); + #elif defined (HAVE_USLEEP) +  usleep (1000); + #else +  sleep (1); + #endif +  THREADS_DISALLOW(); +  } +  +  if (num_kills) { +  fprintf (stderr, "Killed %d thread(s)", num_kills - num_pending_interrupts); +  if (num_pending_interrupts) +  fprintf (stderr, ", %d haven't responded", num_pending_interrupts); +  fputs (".\n", stderr); +  } + } + #endif +    void th_cleanup(void)   {    th_running = 0;       if (Pike_interpreter.thread_state) {    thread_table_delete(Pike_interpreter.thread_state);    Pike_interpreter.thread_state = NULL;    }       if(backend_thread_obj)