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.206 2005/11/15 10:31:40 grubba Exp $ + || $Id: threads.c,v 1.207 2009/03/12 23:44:34 mast Exp $   */      #include "global.h" - RCSID("$Id: threads.c,v 1.206 2005/11/15 10:31:40 grubba Exp $"); + RCSID("$Id: threads.c,v 1.207 2009/03/12 23:44:34 mast Exp $");      PMOD_EXPORT int num_threads = 1;   PMOD_EXPORT int threads_disabled = 0;      /* #define PICKY_MUTEX */      #ifdef _REENTRANT   #include "threads.h"   #include "array.h"   #include "mapping.h"
pike.git/src/threads.c:40:   #endif /* HAVE_SYS_PRCTL_H */      #ifdef HAVE_SYS_TIME_H   #include <sys/time.h>   #endif      #ifndef PIKE_THREAD_C_STACK_SIZE   #define PIKE_THREAD_C_STACK_SIZE (256 * 1024)   #endif    - PMOD_EXPORT int live_threads = 0, disallow_live_threads = 0; + PMOD_EXPORT int live_threads = 0;   PMOD_EXPORT COND_T live_threads_change;   PMOD_EXPORT COND_T threads_disabled_change;   PMOD_EXPORT size_t thread_stack_size=PIKE_THREAD_C_STACK_SIZE;      PMOD_EXPORT void thread_low_error (int errcode)   {    Pike_fatal ("Unexpected error from thread function: %d\n", errcode);   }      /* SCO magic... */
pike.git/src/threads.c:236:   #endif /* HAVE_BROKEN_LINUX_THREAD_EUID */   };      struct thread_local   {    INT32 id;   };      static volatile IMUTEX_T *interleave_list = NULL;    - /* This is a variant of init_threads_disable that blocks all other -  * threads that might run pike code, but still doesn't block the -  * THREADS_ALLOW_UID threads. */ +    void low_init_threads_disable(void)   {    /* Serious black magic to avoid dead-locks */       if (!threads_disabled) {    THREADS_FPRINTF(0,    (stderr, "low_init_threads_disable(): Locking IM's...\n"));       if (Pike_interpreter.thread_id) {    /* Threads have been enabled. */
pike.git/src/threads.c:321:    *! You should make sure that the returned object is freed even if    *! some kind of error is thrown. That means in practice that it    *! should only have references (direct or indirect) from function    *! local variables. Also, it shouldn't be referenced from cyclic    *! memory structures, since those are only destructed by the periodic    *! gc. (This advice applies to mutex locks in general, for that    *! matter.)    */   void init_threads_disable(struct object *o)   { -  disallow_live_threads = 1; +  low_init_threads_disable();       if(live_threads) {    SWAP_OUT_CURRENT_THREAD();    while (live_threads) {    THREADS_FPRINTF(0,    (stderr,    "_disable_threads(): Waiting for %d threads to finish\n",    live_threads));    low_co_wait_interpreter(&live_threads_change);    }    SWAP_IN_CURRENT_THREAD();    } -  -  low_init_threads_disable(); +    }      void exit_threads_disable(struct object *o)   {    THREADS_FPRINTF(0, (stderr, "exit_threads_disable(): threads_disabled:%d\n",    threads_disabled));    if(threads_disabled) {    if(!--threads_disabled) {    IMUTEX_T *im = (IMUTEX_T *)interleave_list;   
pike.git/src/threads.c:358:    THREADS_FPRINTF(0,    (stderr,    "exit_threads_disable(): Unlocking IM 0x%p\n", im));    mt_unlock(&(im->lock));    im = im->next;    }       mt_unlock(&interleave_lock);       THREADS_FPRINTF(0, (stderr, "_exit_threads_disable(): Wake up!\n")); -  disallow_live_threads = 0; +     co_broadcast(&threads_disabled_change);   #ifdef PIKE_DEBUG    threads_disabled_thread = 0;   #endif    }   #ifdef PIKE_DEBUG    } else {    Pike_fatal("exit_threads_disable() called too many times!\n");   #endif /* PIKE_DEBUG */    }