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.198 2003/01/26 11:09:01 mirar Exp $ + || $Id: threads.c,v 1.199 2003/02/08 02:28:40 mast Exp $   */    -  + #ifndef CONFIGURE_TEST   #include "global.h" - RCSID("$Id: threads.c,v 1.198 2003/01/26 11:09:01 mirar Exp $"); + RCSID("$Id: threads.c,v 1.199 2003/02/08 02:28:40 mast Exp $");      PMOD_EXPORT int num_threads = 1;   PMOD_EXPORT int threads_disabled = 0; -  + #endif /* !CONFIGURE_TEST */      #ifdef _REENTRANT -  +  + #ifndef CONFIGURE_TEST +    #include "threads.h"   #include "array.h"   #include "mapping.h"   #include "object.h"   #include "pike_macros.h"   #include "callback.h"   #include "builtin_functions.h"   #include "constants.h"   #include "program.h"   #include "program_id.h"
pike.git/src/threads.c:31:   #include "signal_handler.h"   #include "pike_rusage.h"      #include <errno.h>      PMOD_EXPORT int live_threads = 0, disallow_live_threads = 0;   PMOD_EXPORT COND_T live_threads_change;   PMOD_EXPORT COND_T threads_disabled_change;   PMOD_EXPORT size_t thread_stack_size=256 * 1204;    + #else + #include "pike_threadlib.h" + #endif /* !CONFIGURE_TEST */ +    /* SCO magic... */   int __thread_sys_behavior = 1;    -  + #ifndef CONFIGURE_TEST +    #if !defined(HAVE_PTHREAD_ATFORK) && !defined(th_atfork)   #include "callback.h"   #define PIKE_USE_OWN_ATFORK         static struct callback_list atfork_prepare_callback;   static struct callback_list atfork_parent_callback;   static struct callback_list atfork_child_callback;      int th_atfork(void (*prepare)(void),void (*parent)(void),void (*child)(void))
pike.git/src/threads.c:67:   void th_atfork_parent(void)   {    call_callback(& atfork_parent_callback, 0);   }   void th_atfork_child(void)   {    call_callback(& atfork_child_callback, 0);   }   #endif    + #endif /* !CONFIGURE_TEST */ +    #ifdef __NT__      int low_nt_create_thread(unsigned Pike_stack_size,    unsigned (TH_STDCALL *fun)(void *),    void *arg,    unsigned *id)   {    HANDLE h = (HANDLE)_beginthreadex(NULL, Pike_stack_size, fun, arg, 0, id);    if(h)    {
pike.git/src/threads.c:172: Inside #if defined(SIMULATE_COND_WITH_EVENT)
   mt_lock(& c->lock);    t=c->head;    mt_unlock(& c->lock);    if(t) return -1;    mt_destroy(& c->lock);    return 0;   }      #endif    + #ifdef POSIX_THREADS + pthread_attr_t pattr; + pthread_attr_t small_pattr; + #endif    -  + static void really_low_th_init(void) + { + #ifdef SGI_SPROC_THREADS + #error /* Need to specify a filename */ +  us_cookie = usinit(""); + #endif /* SGI_SPROC_THREADS */ +  + #ifdef POSIX_THREADS + #ifdef HAVE_PTHREAD_INIT +  pthread_init(); + #endif /* HAVE_PTHREAD_INIT */ + #endif /* POSIX_THREADS */ +  + #ifdef POSIX_THREADS +  pthread_attr_init(&pattr); + #ifndef CONFIGURE_TEST + #ifdef HAVE_PTHREAD_ATTR_SETSTACKSIZE +  pthread_attr_setstacksize(&pattr, thread_stack_size); + #endif + #endif +  pthread_attr_setdetachstate(&pattr, PTHREAD_CREATE_DETACHED); +  +  pthread_attr_init(&small_pattr); + #ifdef HAVE_PTHREAD_ATTR_SETSTACKSIZE +  pthread_attr_setstacksize(&small_pattr, 4096*sizeof(char *)); + #endif +  pthread_attr_setdetachstate(&small_pattr, PTHREAD_CREATE_DETACHED); + #endif + } +  + #ifndef CONFIGURE_TEST +    #define THIS_THREAD ((struct thread_state *)CURRENT_STORAGE)      static struct callback *threads_evaluator_callback=0;   int thread_id_result_variable;      int th_running = 0;   #ifdef PIKE_DEBUG   int debug_interpreter_is_locked = 0;   THREAD_T debug_locking_thread;   THREAD_T threads_disabled_thread = 0;   #endif   #ifdef INTERNAL_PROFILING   PMOD_EXPORT unsigned long thread_yields = 0;   #endif   PMOD_EXPORT MUTEX_T interpreter_lock;   MUTEX_T thread_table_lock, interleave_lock;   struct program *mutex_key = 0;   PMOD_EXPORT struct program *thread_id_prog = 0;   struct program *thread_local_prog = 0; - #ifdef POSIX_THREADS - pthread_attr_t pattr; - pthread_attr_t small_pattr; - #endif +    PMOD_EXPORT ptrdiff_t thread_storage_offset;   #ifdef USE_CLOCK_FOR_SLICES   PMOD_EXPORT clock_t thread_start_clock = 0;   #endif      struct thread_starter   {    struct object *id;    struct array *args;   #ifdef HAVE_BROKEN_LINUX_THREAD_EUID
pike.git/src/threads.c:1751:    mt_unlock( &rosie );    new_farmer( fun, here );   }      /*    * Glue code.    */      void low_th_init(void)   { - #ifdef SGI_SPROC_THREADS - #error /* Need to specify a filename */ -  us_cookie = usinit(""); - #endif /* SGI_SPROC_THREADS */ -  +     THREADS_FPRINTF(0, (stderr, "THREADS_DISALLOW() Initializing threads.\n"));    - #ifdef POSIX_THREADS - #ifdef HAVE_PTHREAD_INIT -  pthread_init(); - #endif /* HAVE_PTHREAD_INIT */ - #endif /* POSIX_THREADS */ +  really_low_th_init();       mt_init( & interpreter_lock);    low_mt_lock_interpreter();    mt_init( & thread_table_lock);    mt_init( & interleave_lock);    mt_init( & rosie);    co_init( & live_threads_change);    co_init( & threads_disabled_change); -  +     thread_table_init(); - #ifdef POSIX_THREADS -  pthread_attr_init(&pattr); - #ifdef HAVE_PTHREAD_ATTR_SETSTACKSIZE -  pthread_attr_setstacksize(&pattr, thread_stack_size); - #endif -  pthread_attr_setdetachstate(&pattr, PTHREAD_CREATE_DETACHED); +     -  pthread_attr_init(&small_pattr); - #ifdef HAVE_PTHREAD_ATTR_SETSTACKSIZE -  pthread_attr_setstacksize(&small_pattr, 4096*sizeof(char *)); - #endif -  pthread_attr_setdetachstate(&small_pattr, PTHREAD_CREATE_DETACHED); -  + #ifdef POSIX_THREADS +  /* FIXME: Why set this only when POSIX_THREADS? /mast */    th_running = 1;   #endif   }      void th_init(void)   {    ptrdiff_t mutex_key_offset;      #ifdef UNIX_THREADS   
pike.git/src/threads.c:1970:    thread_id_prog=0;    }      #ifdef PIKE_USE_OWN_ATFORK    free_callback_list(&atfork_prepare_callback);    free_callback_list(&atfork_parent_callback);    free_callback_list(&atfork_child_callback);   #endif   }    + #endif /* !CONFIGURE_TEST */ +    #endif