Branch: Tag:

1998-03-26

1998-03-26 14:31:03 by Henrik Grubbström (Grubba) <grubba@grubba.org>

Improved _disable_threads().
Added THREADS_ALLOW_UID() and THREADS_DISALLOW_UID().

Rev: src/modules/files/efuns.c:1.47
Rev: src/modules/files/file.c:1.83
Rev: src/modules/files/socket.c:1.30
Rev: src/modules/spider/dumudp.c:1.36
Rev: src/modules/system/passwords.c:1.7
Rev: src/modules/system/syslog.c:1.5
Rev: src/modules/system/system.c:1.47
Rev: src/program.c:1.67
Rev: src/threads.c:1.65
Rev: src/threads.h:1.37

45:         extern int num_threads; + extern int live_threads;   struct object;   extern struct object *thread_id;   
221:      extern MUTEX_T interpreter_lock;    + extern COND_T live_threads_change; /* Used by _disable_threads */ + extern COND_T threads_disabled_change; /* Used by _disable_threads */      struct svalue;   struct frame;
338:    struct thread_state *_tmp=(struct thread_state *)thread_id->storage; \    if(num_threads > 1 && !threads_disabled) { \    SWAP_OUT_THREAD(_tmp); \ -  THREADS_FPRINTF((stderr, "THREADS_ALLOW() %s:%d t:%08x\n", \ -  __FILE__, __LINE__, (unsigned int)_tmp->thread_id)); \ +  THREADS_FPRINTF((stderr, "THREADS_ALLOW() %s:%d t:%08x (#%d)\n", \ +  __FILE__, __LINE__, \ +  (unsigned int)_tmp->thread_id, live_threads)); \    mt_unlock(& interpreter_lock); \    } else {} \    HIDE_GLOBAL_VARIABLES()
348:    REVEAL_GLOBAL_VARIABLES(); \    if(_tmp->swapped) { \    mt_lock(& interpreter_lock); \ -  THREADS_FPRINTF((stderr, "THREADS_DISALLOW() %s:%d ... t:%08x\n", \ -  __FILE__, __LINE__, (unsigned int)_tmp->thread_id)); \ +  THREADS_FPRINTF((stderr, "THREADS_DISALLOW() %s:%d... t:%08x (#%d)\n", \ +  __FILE__, __LINE__, \ +  (unsigned int)_tmp->thread_id, live_threads)); \ +  while (threads_disabled) { \ +  THREADS_FPRINTF((stderr, "THREADS_DISALLOW(): Threads disabled\n")); \ +  co_wait(&live_threads_change, &interpreter_lock); \ +  } \    SWAP_IN_THREAD(_tmp);\    } \    } while(0)    -  + #define THREADS_ALLOW_UID() do { \ +  struct thread_state *_tmp_uid=(struct thread_state *)thread_id->storage; \ +  if(num_threads > 1 && !threads_disabled) { \ +  SWAP_OUT_THREAD(_tmp_uid); \ +  live_threads++; \ +  THREADS_FPRINTF((stderr, "THREADS_ALLOW() %s:%d t:%08x (#%d)\n", \ +  __FILE__, __LINE__, \ +  (unsigned int)_tmp_uid->thread_id, live_threads)); \ +  mt_unlock(& interpreter_lock); \ +  } else {} \ +  HIDE_GLOBAL_VARIABLES() +  + #define THREADS_DISALLOW_UID() \ +  REVEAL_GLOBAL_VARIABLES(); \ +  if(_tmp_uid->swapped) { \ +  mt_lock(& interpreter_lock); \ +  live_threads--; \ +  THREADS_FPRINTF((stderr, "THREADS_DISALLOW() %s:%d... t:%08x (#%d)\n", \ +  __FILE__, __LINE__, \ +  (unsigned int)_tmp_uid->thread_id, live_threads)); \ +  while (threads_disabled) { \ +  THREADS_FPRINTF((stderr, "THREADS_DISALLOW(): Threads disabled\n")); \ +  co_signal(&live_threads_change); \ +  co_wait(&threads_disabled_change, &interpreter_lock); \ +  } \ +  SWAP_IN_THREAD(_tmp_uid);\ +  } \ +  } while(0) +    /* Prototypes begin here */   struct thread_starter;   void *new_thread_func(void * data);