pike.git / src / threads.c

version» Context lines:

pike.git/src/threads.c:358:   PMOD_EXPORT int threads_disabled = 0;      #ifdef PIKE_DEBUG   static THREAD_T threads_disabled_thread = 0;   #endif   #ifdef INTERNAL_PROFILING   PMOD_EXPORT unsigned long thread_yields = 0;   #endif   static int th_running = 0;   static MUTEX_T interpreter_lock; + static MUTEX_T interpreter_lock_wanted;   MUTEX_T thread_table_lock;   static MUTEX_T interleave_lock;   static struct program *mutex_key = 0;   PMOD_EXPORT struct program *thread_id_prog = 0;   static struct program *thread_local_prog = 0;   PMOD_EXPORT ptrdiff_t thread_storage_offset;   static int live_threads = 0;   static COND_T live_threads_change;   static COND_T threads_disabled_change;   
pike.git/src/threads.c:404:      #else      #define SET_LOCKING_THREAD 0   static INLINE void check_interpreter_lock (DLOC_DECL) {}      #endif      PMOD_EXPORT INLINE void pike_low_lock_interpreter (DLOC_DECL)   { +  /* The double locking here is to ensure that when a thread releases +  * the interpreter lock, a different thread gets it first. Thereby +  * we ensure a thread switch in check_threads, if there are other +  * threads waiting. */ +  mt_lock (&interpreter_lock_wanted);    mt_lock (&interpreter_lock); -  +  mt_unlock (&interpreter_lock_wanted); +     SET_LOCKING_THREAD;    THREADS_FPRINTF (1, (stderr, "Got iplock" DLOC_PF(" @ ",) "\n"    COMMA_DLOC_ARGS_OPT));   }      PMOD_EXPORT INLINE void pike_low_wait_interpreter (COND_T *cond COMMA_DLOC_DECL)   {    THREADS_FPRINTF (1, (stderr,    "Waiting on cond %p without iplock" DLOC_PF(" @ ",) "\n",    cond COMMA_DLOC_ARGS_OPT)); -  +  +  /* FIXME: Should use interpreter_lock_wanted here as well. The +  * problem is that few (if any) thread libs lets us atomically +  * unlock a mutex and wait, and then lock a different mutex. */    co_wait (cond, &interpreter_lock); -  +     SET_LOCKING_THREAD;    THREADS_FPRINTF (1, (stderr,    "Got signal on cond %p with iplock" DLOC_PF(" @ ",) "\n",    cond COMMA_DLOC_ARGS_OPT));   }      PMOD_EXPORT INLINE int pike_low_timedwait_interpreter (COND_T *cond,    long sec, long nsec    COMMA_DLOC_DECL)   {    int res;    THREADS_FPRINTF (1, (stderr,    "Waiting on cond %p without iplock" DLOC_PF(" @ ",) "\n",    cond COMMA_DLOC_ARGS_OPT)); -  +  +  /* FIXME: Should use interpreter_lock_wanted here as well. The +  * problem is that few (if any) thread libs lets us atomically +  * unlock a mutex and wait, and then lock a different mutex. */    res = co_wait_timeout (cond, &interpreter_lock, sec, nsec); -  +     SET_LOCKING_THREAD;    THREADS_FPRINTF (1, (stderr,    "Got signal on cond %p with iplock" DLOC_PF(" @ ",) "\n",    cond COMMA_DLOC_ARGS_OPT));    return res;   }      static void threads_disabled_wait (DLOC_DECL)   {    assert (threads_disabled);
pike.git/src/threads.c:2859:    * Glue code.    */      void low_th_init(void)   {    THREADS_FPRINTF(0, (stderr, "Initializing threads.\n"));       really_low_th_init();       mt_init( & interpreter_lock); +  mt_init( & interpreter_lock_wanted);    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();       th_running = 1;   }