Branch: Tag:

2000-04-19

2000-04-19 16:14:37 by Martin Stjernholm <mast@lysator.liu.se>

Better debug checks on the interpreter lock.

Rev: src/interpret.c:1.144
Rev: src/interpreter.h:1.41
Rev: src/modules/HTTPLoop/accept_and_parse.c:1.12
Rev: src/modules/HTTPLoop/cache.c:1.9
Rev: src/modules/Java/jvm.c:1.15
Rev: src/modules/files/file.c:1.174
Rev: src/modules/files/sendfile.c:1.38
Rev: src/program.c:1.229
Rev: src/signal_handler.c:1.169
Rev: src/threads.c:1.122
Rev: src/threads.h:1.86

1:   /* -  * $Id: threads.h,v 1.85 2000/04/19 13:57:35 mast Exp $ +  * $Id: threads.h,v 1.86 2000/04/19 16:03:31 mast Exp $    */   #ifndef THREADS_H   #define THREADS_H
260:      extern PIKE_MUTEX_T interpreter_lock;    + #if defined(PIKE_DEBUG) && !defined(__NT__) +  + /* This is a debug wrapper to enable checks that the interpreter lock +  * is hold by the current thread. */ +  + extern THREAD_T debug_locking_thread; + #define SET_LOCKING_THREAD (debug_locking_thread = th_self(), 0) +  + #define mt_lock_interpreter() (mt_lock(&interpreter_lock) || SET_LOCKING_THREAD) + #define mt_trylock_interpreter() (mt_trylock(&interpreter_lock) || SET_LOCKING_THREAD) + #define mt_unlock_interpreter() (mt_unlock(&interpreter_lock)) + #define co_wait_interpreter(COND) \ +  do {co_wait((COND), &interpreter_lock); SET_LOCKING_THREAD;} while (0) +  + #define CHECK_INTERPRETER_LOCK() do { \ +  if (th_running) { \ +  THREAD_T self; \ +  if (!mt_trylock(&interpreter_lock)) \ +  fatal("Interpreter is not locked.\n"); \ +  self = th_self(); \ +  if (!th_equal(debug_locking_thread, self)) \ +  fatal("Interpreter is not locked by this thread.\n"); \ +  } \ + } while (0) +  + #else +  + #define mt_lock_interpreter() (mt_lock(&interpreter_lock)) + #define mt_trylock_interpreter() (mt_trylock(&interpreter_lock)) + #define mt_unlock_interpreter() (mt_unlock(&interpreter_lock)) + #define co_wait_interpreter(COND) do {co_wait((COND), &interpreter_lock);} while (0) +  + #define CHECK_INTERPRETER_LOCK() do {} while (0) +  + #endif +    extern COND_T live_threads_change; /* Used by _disable_threads */   extern COND_T threads_disabled_change; /* Used by _disable_threads */   
478:    THREADS_FPRINTF(1, (stderr, "THREADS_ALLOW() %s:%d t:%08x(#%d)\n", \    __FILE__, __LINE__, \    (unsigned int)_tmp->thread_id, live_threads)); \ -  mt_unlock(& interpreter_lock); \ +  mt_unlock_interpreter(); \    } else {} \    HIDE_GLOBAL_VARIABLES()      #define THREADS_DISALLOW() \    REVEAL_GLOBAL_VARIABLES(); \    if(_tmp->swapped) { \ -  mt_lock(& interpreter_lock); \ +  mt_lock_interpreter(); \    THREADS_FPRINTF(1, (stderr, "THREADS_DISALLOW() %s:%d t:%08x(#%d)\n", \    __FILE__, __LINE__, \    (unsigned int)_tmp->thread_id, live_threads)); \    while (threads_disabled) { \    THREADS_FPRINTF(1, (stderr, \    "THREADS_DISALLOW(): Threads disabled\n")); \ -  co_wait(&threads_disabled_change, &interpreter_lock); \ +  co_wait_interpreter(&threads_disabled_change); \    } \    SWAP_IN_THREAD(_tmp);\    } \
514:    THREADS_FPRINTF(1, (stderr, "THREADS_ALLOW_UID() %s:%d t:%08x(#%d)\n", \    __FILE__, __LINE__, \    (unsigned int)_tmp_uid->thread_id, live_threads)); \ -  mt_unlock(& interpreter_lock); \ +  mt_unlock_interpreter(); \    } else {} \    HIDE_GLOBAL_VARIABLES()      #define THREADS_DISALLOW_UID() \    REVEAL_GLOBAL_VARIABLES(); \    if(_tmp_uid->swapped) { \ -  mt_lock(& interpreter_lock); \ +  mt_lock_interpreter(); \    live_threads--; \    THREADS_FPRINTF(1, (stderr, \    "THREADS_DISALLOW_UID() %s:%d t:%08x(#%d)\n", \
530:    co_broadcast(&live_threads_change); \    while (threads_disabled) { \    THREADS_FPRINTF(1, (stderr, "THREADS_DISALLOW_UID(): Wait...\n")); \ -  co_wait(&threads_disabled_change, &interpreter_lock); \ +  co_wait_interpreter(&threads_disabled_change); \    } \    SWAP_IN_THREAD(_tmp_uid);\    } \
542:    THREADS_DISALLOW()      #ifdef PIKE_DEBUG -  +    #define ASSERT_THREAD_SWAPPED_IN() do { \    struct thread_state *_tmp=thread_state_for_id(th_self()); \    if(_tmp->swapped) fatal("Thread is not swapped in!\n"); \    }while(0)    - #ifdef __NT__ - #define TRYLOCK_INTERPRETER_LOCK() do {} while (0) +    #else - #define TRYLOCK_INTERPRETER_LOCK() do { \ -  if (th_running && !mt_trylock(&interpreter_lock)) \ -  fatal("Haven't got interpreter lock.\n"); \ - } while (0) - #endif -  - #define CHECK_INTERPRETER_LOCK() do { \ -  if (th_running) { \ -  THREAD_T self; \ -  TRYLOCK_INTERPRETER_LOCK(); \ -  self = th_self(); \ -  if( thread_id && !th_equal( OBJ2THREAD(thread_id)->id, self) ) \ -  fatal("Current thread is wrong.\n"); \ -  } \ - } while (0) -  - #else -  +    #define ASSERT_THREAD_SWAPPED_IN() - #define CHECK_INTERPRETER_LOCK() do {} while (0) -  +    #endif      /* Prototypes begin here */
663:   #define init_threads_disable(X)   #define exit_threads_disable(X)    - #define TRYLOCK_INTERPRETER_LOCK() do {} while (0) - #define CHECK_INTERPRETER_LOCK() do {} while (0) -  +    #endif /* PIKE_THREADS */      #ifdef __NT__