Add a catatonia timer.
authorGuillermo J. Rozas <edu/mit/csail/zurich/gjr>
Sat, 4 Sep 1993 07:08:54 +0000 (07:08 +0000)
committerGuillermo J. Rozas <edu/mit/csail/zurich/gjr>
Sat, 4 Sep 1993 07:08:54 +0000 (07:08 +0000)
v7/src/microcode/ntgui.c
v7/src/microcode/ntgui.h
v7/src/microcode/ntscmlib.h
v7/src/microcode/ntscreen.c
v7/src/microcode/ntscreen.h
v7/src/microcode/ntsig.c
v7/src/microcode/nttop.c
v7/src/microcode/ntutl/makefile
v7/src/microcode/ntutl/scheme16.c
v7/src/microcode/ntutl/scheme31.c
v7/src/microcode/ntutl/scheme32.c

index 8cdb4ff83575294de44ea6ebf1c48cb0e4439fb5..a9542e9a3a1cda32f1b470f8c5cd463513ac8373 100644 (file)
@@ -1,6 +1,6 @@
 /* -*-C-*-
 
-$Id: ntgui.c,v 1.8 1993/09/03 17:56:44 gjr Exp $
+$Id: ntgui.c,v 1.9 1993/09/04 07:03:43 gjr Exp $
 
 Copyright (c) 1993 Massachusetts Institute of Technology
 
@@ -32,15 +32,15 @@ Technology nor of any adaptation thereof in any advertising,
 promotional, or sales literature without prior written consent from
 MIT in each case. */
 
+#include <string.h>
+#include <stdarg.h>
 #include "scheme.h"
 #include "prims.h"
-#include "nt.h"
 #include "os.h"
+#include "nt.h"
+#include "ntdialog.h"
 #include "ntgui.h"
 #include "ntscreen.h"
-#include "ntdialog.h"
-#include <string.h>
-#include <stdarg.h>
 \f
 extern /*static*/ HANDLE  ghInstance = 0;
 
@@ -189,21 +189,35 @@ DEFUN_VOID (nt_gui_default_poll)
 }
 \f
 extern HANDLE master_tty_window;
+extern void catatonia_trigger (void);
+
+void
+catatonia_trigger (void)
+{
+  if ((MessageBox (master_tty_window,
+                  "Scheme appears to have become catatonic.\n"
+                  "OK to kill it?",
+                  "MIT Scheme",
+                  (MB_ICONSTOP | MB_OKCANCEL)))
+      == IDOK)
+  {
+    extern void termination_normal (int);
+    termination_normal (0);
+  }
+  else
+  {
+    Registers[REGBLOCK_CATATONIA_COUNTER] = 0;
+    return;
+  }
+}
 
 static void
 nt_gui_high_priority_poll (void)
 {
   MSG close_msg;
 
-  if (PeekMessage (&close_msg,
-                  master_tty_window,
-#if 0
-                  WM_HOTKEY,
-                  (WM_HOTKEY + 1),
-#else
-                  WM_CLOSE,
-                  (WM_CLOSE + 1),
-#endif
+  if (PeekMessage (&close_msg, master_tty_window,
+                  WM_CATATONIC, (WM_CATATONIC + 1),
                   PM_REMOVE))
   {
     MIT_TranslateMessage (&close_msg);
@@ -211,7 +225,7 @@ nt_gui_high_priority_poll (void)
   }
   return;
 }
-
+\f
 DEFINE_PRIMITIVE ("MICROCODE-POLL-INTERRUPT-HANDLER",
                   Prim_microcode_poll_interrupt_handler, 2, 2,
                  "NT High-priority timer interrupt handler for Windows I/O.")
@@ -228,6 +242,7 @@ DEFINE_PRIMITIVE ("MICROCODE-POLL-INTERRUPT-HANDLER",
   }
   else
   {
+    Registers[REGBLOCK_CATATONIA_COUNTER] = 0;
     nt_gui_default_poll ();
 #ifndef USE_WM_TIMER
     low_level_timer_tick ();
@@ -247,6 +262,8 @@ DEFINE_PRIMITIVE ("NT-DEFAULT-POLL-GUI", Prim_nt_default_poll_gui, 2, 2,
   }
 }
 
+extern void EXFUN (NT_gui_init, (void));
+
 void
 DEFUN_VOID (NT_gui_init)
 {
index 1b2566ae5d4acce59ed8214dec0290fdb4057358..4608e7f1705549205d738d757a772b62e75700cb 100644 (file)
@@ -1,6 +1,6 @@
 /* -*-C-*-
 
-$Id: ntgui.h,v 1.3 1993/06/24 02:14:39 gjr Exp $
+$Id: ntgui.h,v 1.4 1993/09/04 07:04:23 gjr Exp $
 
 Copyright (c) 1993 Massachusetts Institute of Technology
 
@@ -35,8 +35,6 @@ MIT in each case. */
 #ifndef SCM_NTGUI_H
 #define SCM_NTGUI_H
 \f
-void EXFUN (NT_gui_init, (void));
-
 #define IDM_NEW            100
 #define IDM_OPEN           101
 #define IDM_SAVE           102
@@ -56,4 +54,12 @@ void EXFUN (NT_gui_init, (void));
 #define IDM_ABOUT          303
 #define IDM_EMERGENCYKILL  400
 
+#ifndef REGBLOCK_CATATONIA_COUNTER
+/* They must be contiguous, with counter being lower. */
+# define REGBLOCK_CATATONIA_COUNTER REGBLOCK_MINIMUM_LENGTH
+# define REGBLOCK_CATATONIA_LIMIT   (REGBLOCK_MINIMUM_LENGTH + 1)
+#endif
+
+#define WM_CATATONIC (WM_USER)
+
 #endif /* SCM_NTGUI_H */
index 5cf2fdced598869f8422714629e5f8e80a2b31ce..9ca34d25f9e493f7ebdb9cadbb2251afe58d6c22 100644 (file)
@@ -1,6 +1,6 @@
 /* -*-C-*-
 
-$Id: ntscmlib.h,v 1.2 1993/08/21 03:38:52 gjr Exp $
+$Id: ntscmlib.h,v 1.3 1993/09/04 07:01:36 gjr Exp $
 
 Copyright (c) 1993 Massachusetts Institute of Technology
 
@@ -70,12 +70,16 @@ extern void
                            unsigned long);             /* size */
 
 extern UINT
-  win32_install_async_timer (unsigned long *,          /* regs */
+  win32_install_async_timer (void **,                  /* timer state */
+                            unsigned long *,           /* regs */
                             unsigned long,             /* memtop off */
                             unsigned long,             /* int_code off */
                             unsigned long,             /* int_mask off */
                             unsigned long,             /* mask */
-                            void **);                  /* timer state */
+                            unsigned long,             /* ctr_off */
+                            unsigned long,             /* message */
+                            HWND);                     /* window */
+
 extern void
   win32_flush_async_timer (void *);
 
@@ -136,12 +140,15 @@ struct ntw32lib_vulock_s
 #define NTW32LIB_INSTALL_TIMER         3
 struct ntw32lib_itimer_s
 {
+  SCM_ULONG handle;            /* ->32 */
   SCM_ULPTR base;              /* ->16 */
   SCM_ULONG memtop_off;                /* ->16 */
   SCM_ULONG int_code_off;      /* ->16 */
   SCM_ULONG int_mask_off;      /* ->16 */
   SCM_ULONG bit_mask;          /* ->16 */
-  SCM_ULONG handle;            /* ->32 */
+  SCM_ULONG ctr_off;           /* ->16 */
+  SCM_ULONG message;           /* ->16 */
+  SCM_ULONG window;            /* ->16 */
 };
 
 #define NTW32LIB_FLUSH_TIMER           4
index eaa9c4870426eea8291257629042d7a506e21d30..0ca47828057c9bad59f3fe2acec5023ef8836099 100644 (file)
@@ -1,6 +1,6 @@
 /* -*-C-*-
 
-$Id: ntscreen.c,v 1.14 1993/09/03 18:01:28 gjr Exp $
+$Id: ntscreen.c,v 1.15 1993/09/04 07:06:52 gjr Exp $
 
 Copyright (c) 1993 Massachusetts Institute of Technology
 
@@ -34,6 +34,7 @@ MIT in each case. */
 
 #include <stdlib.h>
 #include "ntscreen.h"
+#include "ntgui.h"
 //#include "screen.rh"
 /* Allow conditionalization for underlying OS. */
 extern BOOL win32_under_win32s_p (void);
@@ -629,6 +630,13 @@ ScreenWndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
          DestroyScreenInfo (hWnd);
          break ;
 
+      case WM_CATATONIC:
+      {
+       extern void catatonia_trigger (void);
+       catatonia_trigger ();
+       break;
+      }
+
       case WM_CLOSE:
       {
        extern HANDLE master_tty_window;
index fd3a005ccb21060890117f042b80e43d9bb63f25..dd2222de01ff7829f156282ef340e21d50a77cea 100644 (file)
@@ -1,6 +1,6 @@
 /* -*-C-*-
 
-$Id: ntscreen.h,v 1.7 1993/09/03 17:57:40 gjr Exp $
+$Id: ntscreen.h,v 1.8 1993/09/04 07:06:11 gjr Exp $
 
 Copyright (c) 1993 Massachusetts Institute of Technology
 
@@ -166,7 +166,7 @@ BOOL  Screen_PeekEvent (HANDLE, SCREEN_EVENT *);
 //---------------------------------------------------------------------------
 
 #ifndef SCREEN_COMMAND_FIRST
-#define SCREEN_COMMAND_FIRST   WM_USER
+#define SCREEN_COMMAND_FIRST   (WM_USER + 10)
 #endif
 
 #define SCREEN_WRITE           (SCREEN_COMMAND_FIRST+0)
index 93f98c3852ea8713db5da5c2765cb05b338551aa..b4cd1c0bcf01a02d20196f5b25d20f59c2fa1aa1 100644 (file)
@@ -1,6 +1,6 @@
 /* -*-C-*-
 
-$Id: ntsig.c,v 1.9 1993/09/03 18:02:29 gjr Exp $
+$Id: ntsig.c,v 1.10 1993/09/04 07:08:22 gjr Exp $
 
 Copyright (c) 1992-1993 Massachusetts Institute of Technology
 
@@ -38,17 +38,18 @@ MIT in each case. */
 */
 
 #include "scheme.h"
-#include "nt.h"
-#include <signal.h>
+#include "critsec.h"
 #include "ossig.h"
 #include "osctty.h"
 #include "ostty.h"
-#include "critsec.h"
-#include "ntsys.h"
+#include "nt.h"
+#include "ntgui.h"
 #include "ntio.h"
-#include "extern.h"
-#include "ntscreen.h"
 #include "ntscmlib.h"
+#include "ntscreen.h"
+#include "ntsys.h"
+
+extern HANDLE master_tty_window;
 \f
 /* Signal mask manipulation */
 
@@ -156,7 +157,6 @@ master_tty_interrupt (HWND tty, WORD command)
 static void
 DEFUN_VOID (update_interrupt_characters)
 {
-  extern HANDLE master_tty_window;
   int i;
 
   for (i = 0; i < KB_INT_TABLE_SIZE; i++)
@@ -402,29 +402,32 @@ DEFUN_VOID (OS_restartable_exit)
   return;
 }
 \f
-/* Timer interrupt */
+/* System-level timer interrupt */
 
-/* Why does this raise INT_Timer as well?
-   We could request an synchronous Windows timer that would trigger
-   the timer interrupt bit.  -- This does not seem to work!
-
-   INT_Global_GC: High-priority Windows polling interrupt.
+/* INT_Global_GC: High-priority Windows polling interrupt.
    INT_Global_1:  Windows polling interrupt.
-   INT_Timer:     Thread-switch timer interrupt.
  */
 
+#define CATATONIA_PERIOD       60000   /* msec */
+#define ASYNC_TIMER_PERIOD     50      /* msec */
+
 static void * timer_state = ((void *) NULL);
 
 static char *
 DEFUN_VOID (install_timer)
 {
-  switch (win32_install_async_timer (&Registers[0],
+  Registers[REGBLOCK_CATATONIA_COUNTER] = 0;
+  Registers[REGBLOCK_CATATONIA_LIMIT]
+    = (CATATONIA_PERIOD / ASYNC_TIMER_PERIOD);
+  switch (win32_install_async_timer (&timer_state,
+                                    &Registers[0],
                                     REGBLOCK_MEMTOP,
                                     REGBLOCK_INT_CODE,
                                     REGBLOCK_INT_MASK,
-                                    (INT_Global_GC
-                                     | INT_Global_1),
-                                    &timer_state))
+                                    (INT_Global_GC | INT_Global_1),
+                                    REGBLOCK_CATATONIA_COUNTER,
+                                    WM_CATATONIC,
+                                    master_tty_window))
   {
     case WIN32_ASYNC_TIMER_OK:
       return (NULL);
index e7e1e9f2ae5070bd8509374fea6ccff7af599980..c2f198056643b8e0066d8dde47fef87c9029a879 100644 (file)
@@ -1,6 +1,6 @@
 /* -*-C-*-
 
-$Id: nttop.c,v 1.9 1993/09/03 18:04:32 gjr Exp $
+$Id: nttop.c,v 1.10 1993/09/04 07:08:54 gjr Exp $
 
 Copyright (c) 1993 Massachusetts Institute of Technology
 
@@ -33,7 +33,6 @@ promotional, or sales literature without prior written consent from
 MIT in each case. */
 
 #include "nt.h"
-#include "ntgui.h"
 #include "nttop.h"
 #include "osctty.h"
 #include "prims.h"
@@ -43,6 +42,7 @@ MIT in each case. */
 
 extern void EXFUN (execute_reload_cleanups, (void));
 
+extern void EXFUN (NT_gui_init, (void));
 extern void EXFUN (NT_initialize_channels, (void));
 extern void EXFUN (NT_initialize_directory_reader, (void));
 extern void EXFUN (NT_initialize_signals, (void));
index cedc91619f4ad2d125c48084d46b0a7085eaae40..c9c12ae8c78110ce304d8620e8b0a1dbb57b6207 100644 (file)
@@ -1,6 +1,6 @@
 ### -*- Fundamental -*-
 ###
-###    $Id: makefile,v 1.11 1993/09/03 17:50:09 gjr Exp $
+###    $Id: makefile,v 1.12 1993/09/04 06:59:05 gjr Exp $
 ###
 ###    Copyright (c) 1992-1993 Massachusetts Institute of Technology
 ###
@@ -413,16 +413,17 @@ NT_DEPENDENCIES = oscond.h ansidecl.h posixtyp.h intext.h \
 ntenv.obj : scheme.tch osenv.h ntscreen.h $(NT_DEPENDENCIES)
 ntfile.obj : osfile.h osio.h ntio.h $(NT_DEPENDENCIES)
 ntfs.obj : osfs.h $(NT_DEPENDENCIES)
-ntio.obj : osio.h ntio.h $(NT_DEPENDENCIES)
+ntio.obj : osio.h ntio.h ntscreen.h $(NT_DEPENDENCIES)
 nttop.obj : ostop.h nttop.h osctty.h errors.h option.h $(NT_DEPENDENCIES)
 nttty.obj : ostty.h osenv.h osio.h ntio.h osterm.h ntterm.h $(NT_DEPENDENCIES)
-ntsig.obj : ossig.h osctty.h ostty.h critsec.h $(NT_DEPENDENCIES) ntscmlib.h
+ntsig.obj : ossig.h osctty.h ostty.h critsec.h \
+       $(NT_DEPENDENCIES) ntgui.h ntio.h ntscmlib.h ntscreen.h
 nttrap.obj: nttrap.h ntscmlib.h $(GC_HEAD_FILES) $(NT_DEPENDENCIES)
 ntsys.obj: ntsys.h
-ntgui.obj : ntgui.c ntdialog.h ntscreen.h $(NT_DEPENDENCIES) scheme.tch
+ntgui.obj : ntgui.c ntdialog.h ntgui.h ntscreen.h $(NT_DEPENDENCIES) scheme.tch
 ntasutl.obj : ntasutl.asm
 ntkbutl.obj : ntkbutl.asm
-ntscreen.obj : ntscreen.c ntscreen.h
+ntscreen.obj : ntscreen.c ntgui.h ntscreen.h
 prntenv.obj : $(NT_DEPENDENCIES)
 prntfs.obj : $(NT_DEPENDENCIES) scheme.tch prims.h osfs.h
 prntio.obj : $(NT_DEPENDENCIES) scheme.tch prims.h ntio.h osio.h syscall.h
index 72520e4427720aefcfc051fc40c21a056df28440..264d5757fc832bda3b4837929f8668ecb0778337 100644 (file)
@@ -1,6 +1,6 @@
 /* -*-C-*-
 
-$Id: scheme16.c,v 1.4 1993/08/24 04:53:32 gjr Exp $
+$Id: scheme16.c,v 1.5 1993/09/04 06:59:59 gjr Exp $
 
 Copyright (c) 1993 Massachusetts Institute of Technology
 
@@ -305,18 +305,20 @@ MK_FP (unsigned short seg, unsigned short off)
 
 static WORD htimer = 0;
 static unsigned long timer_index = 0;
-
 static WORD (FAR PASCAL * KillSystemTimer) (WORD htimer);
 
 static struct ntw16lib_itimer_s
 {
   struct ntw16lib_itimer_s FAR * next;
+  unsigned long index;
   unsigned long FAR * base;
   unsigned long memtop_off;
   unsigned long int_code_off;
   unsigned long int_mask_off;
   unsigned long bit_mask;
-  unsigned long index;
+  unsigned long ctr_off;
+  UINT message;
+  HWND window;
   UINT selector;
   HGLOBAL ghan;
 } FAR * async_timers = ((struct ntw16lib_itimer_s FAR *) NULL);
@@ -333,17 +335,28 @@ scheme_asynctimer (void)
         & scm_timer->bit_mask)
        != 0)
       scm_timer->base[scm_timer->memtop_off] = ((unsigned long) -1L);
+    scm_timer->base[scm_timer->ctr_off] += 1L;
+    if ((scm_timer->base[scm_timer->ctr_off]
+        > scm_timer->base[scm_timer->ctr_off + 1])
+       && (scm_timer->base[scm_timer->ctr_off + 1] != 0))
+    {
+      PostMessage (scm_timer->window,
+                  scm_timer->message,
+                  ((WPARAM) 0),
+                  ((LPARAM) 0));
+      scm_timer->base[scm_timer->ctr_off] = 0L;
+    }
     scm_timer = scm_timer->next;
   }
   return;
 }
-
+\f
 static void
 scheme_asynctimer_end (void)
 {
   return;
 }
-\f
+
 static void
 possibly_uninstall_async_handler (void)
 {
@@ -475,14 +488,17 @@ win16_install_timer (struct ntw32lib_itimer_s FAR * buf)
     return (WIN32_ASYNC_TIMER_NOLDT);
   }
 
-  scm_timer->ghan = ghan;
+  scm_timer->next = async_timers;
+  scm_timer->index = timer_index++;
   scm_timer->base = (MK_FP (scm_timer->selector, (FP_OFF (buf->base))));
   scm_timer->memtop_off = buf->memtop_off;
   scm_timer->int_code_off = buf->int_code_off;
   scm_timer->int_mask_off = buf->int_mask_off;
   scm_timer->bit_mask = buf->bit_mask;
-  scm_timer->index = timer_index++;
-  scm_timer->next = async_timers;
+  scm_timer->ctr_off = buf->ctr_off;
+  scm_timer->message = ((UINT) buf->message);
+  scm_timer->window = ((HWND) buf->window);
+  scm_timer->ghan = ghan;
 
   buf->handle = scm_timer->index;
   async_timers = scm_timer;
index 882abb52394c4f44891948654c80045e202eabd0..2ef62daec90ba33ec96db1e7ddb5de6de2036f05 100644 (file)
@@ -1,6 +1,6 @@
 /* -*-C-*-
 
-$Id: scheme31.c,v 1.3 1993/08/24 04:51:20 gjr Exp $
+$Id: scheme31.c,v 1.4 1993/09/04 07:00:37 gjr Exp $
 
 Copyright (c) 1993 Massachusetts Institute of Technology
 
@@ -167,12 +167,15 @@ win32_unlock_memory_area (LPVOID area, unsigned long size)
 }
 \f
 UINT
-win32_install_async_timer (unsigned long * base,
+win32_install_async_timer (void ** state_ptr,
+                          unsigned long * base,
                           unsigned long memtop_off,
                           unsigned long int_code_off,
                           unsigned long int_mask_off,
                           unsigned long bit_mask,
-                          void ** state_ptr)
+                          unsigned long ctr_off,
+                          unsigned long message,
+                          HWND window)
 {
   struct ntw32lib_itimer_s param;
   LPVOID translation[2];
@@ -183,6 +186,9 @@ win32_install_async_timer (unsigned long * base,
   param.int_code_off = ((SCM_ULONG) int_code_off);
   param.int_mask_off = ((SCM_ULONG) int_mask_off);
   param.bit_mask = ((SCM_ULONG) bit_mask);
+  param.ctr_off = ((SCM_ULONG) ctr_off);
+  param.message = ((SCM_ULONG) message);
+  param.window = ((SCM_ULONG) window);
 
   translation[0] = ((LPVOID) & param.base);
   translation[1] = ((LPVOID) NULL);
index 357017d15afe92d5f20aa82bd9233e58375fdbc8..650598ede55f0a59e8b894606640abfa9049e98e 100644 (file)
@@ -1,6 +1,6 @@
 /* -*-C-*-
 
-$Id: scheme32.c,v 1.4 1993/09/03 17:50:59 gjr Exp $
+$Id: scheme32.c,v 1.5 1993/09/04 07:01:12 gjr Exp $
 
 Copyright (c) 1993 Massachusetts Institute of Technology
 
@@ -90,6 +90,9 @@ struct win32_timer_closure_s
   unsigned long int_code_off;
   unsigned long int_mask_off;
   unsigned long bit_mask;
+  unsigned long ctr_off;
+  unsigned long message;
+  HWND window;
 };
 
 static void _stdcall
@@ -103,6 +106,17 @@ win32_nt_timer_tick (UINT wID, UINT wMsg, DWORD dwUser, DWORD dw1, DWORD dw2)
        & timer_closure->bit_mask)
       != 0)
     timer_closure->block[timer_closure->memtop_off] = ((unsigned long) -1);
+  timer_closure->block[timer_closure->ctr_off] += 1;
+  if ((timer_closure->block[timer_closure->ctr_off]
+       > timer_closure->block[timer_closure->ctr_off + 1])
+      && (timer_closure->block[timer_closure->ctr_off + 1] != 0))
+  {
+    PostMessage (timer_closure->window,
+                timer_closure->message,
+                ((WPARAM) 0),
+                ((LPARAM) 0));
+    timer_closure->block[timer_closure->ctr_off] = 0;
+  }
   return;
 }
 
@@ -126,12 +140,15 @@ win32_flush_async_timer (void * state)
 }
 \f
 UINT
-win32_install_async_timer (unsigned long * block,
+win32_install_async_timer (void ** state_ptr,
+                          unsigned long * block,
                           unsigned long memtop_off,
                           unsigned long int_code_off,
                           unsigned long int_mask_off,
                           unsigned long bit_mask,
-                          void ** state_ptr)
+                          unsigned long ctr_off,
+                          unsigned long message,
+                          HWND window)
 {
   TIMECAPS tc;
   UINT wTimerRes;
@@ -152,12 +169,15 @@ win32_install_async_timer (unsigned long * block,
   if (timer_closure == ((struct win32_timer_closure_s *) NULL))
     return (WIN32_ASYNC_TIMER_NOMEM);
 
+  timer_closure->timer_id = 0;
   timer_closure->block = block;
   timer_closure->memtop_off = memtop_off;
   timer_closure->int_code_off = int_code_off;
   timer_closure->int_mask_off = int_mask_off;
   timer_closure->bit_mask = bit_mask;
-  timer_closure->timer_id = 0;
+  timer_closure->ctr_off = ctr_off;
+  timer_closure->message = message;
+  timer_closure->window = window;
 
   if ((! (VirtualLock (((void *) timer_closure),
                       (sizeof (struct win32_timer_closure_s)))))