pike.git / src / threads.c

version» Context lines:

pike.git/src/threads.c:389:    INT32 id;   };      static volatile IMUTEX_T *interleave_list = NULL;      #define THREADSTATE2OBJ(X) ((X)->thread_obj)      #if defined(PIKE_DEBUG)      /* This is a debug wrapper to enable checks that the interpreter lock -  * is hold by the current thread. */ +  * is held by the current thread. */ + static int debug_is_locked;   static THREAD_T debug_locking_thread; - #define SET_LOCKING_THREAD (debug_locking_thread = th_self()) + #define SET_LOCKING_THREAD (debug_is_locked = 1, \ +  debug_locking_thread = th_self()) + #define UNSET_LOCKING_THREAD (debug_is_locked = 0)   static INLINE void check_interpreter_lock (DLOC_DECL)   {    if (th_running) {    THREAD_T self; -  if (!mt_trylock (&interpreter_lock)) +  if (!debug_is_locked)    pike_fatal_dloc ("Interpreter not locked.\n");    self = th_self();    if (!th_equal (debug_locking_thread, self))    pike_fatal_dloc ("Interpreter not locked by this thread.\n");    }   }      #else      #define SET_LOCKING_THREAD 0 -  + #define UNSET_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. */
pike.git/src/threads.c:431:    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)); +  UNSET_LOCKING_THREAD;       /* 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)); -  +  UNSET_LOCKING_THREAD;       /* 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);    do {    THREADS_FPRINTF (1, (stderr,    "Waiting on threads_disabled" DLOC_PF(" @ ",) "\n"    COMMA_DLOC_ARGS_OPT)); -  +  UNSET_LOCKING_THREAD;    co_wait (&threads_disabled_change, &interpreter_lock);    SET_LOCKING_THREAD;    } while (threads_disabled);    THREADS_FPRINTF (1, (stderr,    "Continue after threads_disabled" DLOC_PF(" @ ",) "\n"    COMMA_DLOC_ARGS_OPT));   }      PMOD_EXPORT INLINE void pike_lock_interpreter (DLOC_DECL)   {    pike_low_lock_interpreter (DLOC_ARGS_OPT);    if (threads_disabled) threads_disabled_wait (DLOC_ARGS_OPT);   }      PMOD_EXPORT INLINE void pike_unlock_interpreter (DLOC_DECL)   {    THREADS_FPRINTF (1, (stderr, "Releasing iplock" DLOC_PF(" @ ",) "\n"    COMMA_DLOC_ARGS_OPT)); -  +  UNSET_LOCKING_THREAD;    mt_unlock (&interpreter_lock);   }      PMOD_EXPORT INLINE void pike_wait_interpreter (COND_T *cond COMMA_DLOC_DECL)   {    pike_low_wait_interpreter (cond COMMA_DLOC_ARGS_OPT);    if (threads_disabled) threads_disabled_wait (DLOC_ARGS_OPT);   }      PMOD_EXPORT INLINE int pike_timedwait_interpreter (COND_T *cond,