From 377a6f3f47ae871e88b03fd7c39048a8c3aebc96 Mon Sep 17 00:00:00 2001 From: Nick Briggs Date: Thu, 2 Sep 2021 12:42:51 -0700 Subject: [PATCH] Rewrite keyboard and async I/O handling to improve performance and reduce dependency on async I/O signals (#392) * Rewrite keyboard and async I/O handling to improve performance and reduce dependency on async I/O signals Replaces the SIGIO handler, which used to process X events in the interrupt context, with a stub routine that sets a flag to signal processing is required. Actual event processing is moved to the main dispatch loop where Lisp periodic interrupts are handled. Removes the X connection file descriptor from the set of fds contributing to SIGIO events and moves the processing of X events to where the Lisp periodic interrupt is handled in the main dispatch loop. This code is already guarded by a check for XPending() so can be called regardless of whether any file descriptors are known to be ready. Actual processing of async I/O events and X events are handled by procedures process_io_events() and process_Xevents() respectively. For the most part these are a renaming of getsignaldata() and getXsignaldata(). The Lisp periodic timer (VTALRM) was set to operate with a 25000 us period (40 Hz), but on modern hardware it is possible to run this timer with a period of 10000 us (100 Hz) Incidentally, a bug was noted (and fixed) in the X event handling code for motion events: Mouse motion without any keyboard activity should not add an entry to the keyboard event ring buffer as these events do not represent a key state change. Since the ring buffer is of limited size, when it is filled new events are ignored until the buffered events are processed. This resulted in the loss of a key/mouse button transition (up or down) if the mouse was moved about "too much" between keyboard events. A few incidental cleanups were also made: - KBDEventFlg initialization fixed (wrong semantic type) - Event_Req renamed to IO_Signalled (more appropriate name) - int_io_open() sets up process (self) to handle SIGIO generated by O_ASYNC operations - LOCK_X_EVENTS turned off since X library calls can no longer happen in an interrupt context * Use of O_ASYNC must depend on the symbol being defined (looking at you, Cygwin) * Add SA_RESTART flag to sigaction for SIGVTALRM periodic interrupt * LOCK_X_UPDATE is no longer needed and should not be defined by default for Solaris in version.h --- CMakeLists.txt | 2 +- bin/makefile-cygwin.x86_64-x | 2 +- bin/makefile-darwin.386-x | 4 +- bin/makefile-darwin.aarch64-x | 2 +- bin/makefile-darwin.ppc-x | 2 +- bin/makefile-darwin.x86_64-x | 2 +- bin/makefile-freebsd.386-x | 2 +- bin/makefile-freebsd.aarch64-x | 2 +- bin/makefile-freebsd.x86_64-x | 2 +- bin/makefile-init-darwin.386 | 2 +- bin/makefile-init-darwin.aarch64 | 2 +- bin/makefile-init-darwin.x86_64 | 2 +- bin/makefile-init-freebsd.386 | 2 +- bin/makefile-init-freebsd.aarch64 | 2 +- bin/makefile-init-freebsd.x86_64 | 2 +- bin/makefile-init-linux.x86_64 | 2 +- bin/makefile-init-sunos5.sparc | 4 +- bin/makefile-linux.386-x | 2 +- bin/makefile-linux.aarch64-x | 2 +- bin/makefile-linux.armv7l-x | 2 +- bin/makefile-linux.x86_64-x | 2 +- bin/makefile-openbsd.x86_64-x | 2 +- bin/makefile-sunos5.386-x | 3 +- bin/makefile-sunos5.i386-x | 3 +- bin/makefile-sunos5.sparc-x | 4 +- bin/makefile-sunos5.x86_64-x | 3 +- inc/keyeventdefs.h | 2 +- inc/version.h | 1 - inc/xwinmandefs.h | 2 +- src/keyevent.c | 65 +++++-------------------------- src/rs232c.c | 2 +- src/timer.c | 50 ++++++++++++------------ src/xc.c | 29 ++++++++------ src/xinit.c | 11 +----- src/xlspwin.c | 2 +- src/xwinman.c | 8 ++-- 36 files changed, 90 insertions(+), 143 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fb766ce..821b305 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,7 +43,7 @@ OPTION(MAIKO_DISPLAY_X11 "Use X11 for display." ON) IF(MAIKO_DISPLAY_X11) FIND_PACKAGE(X11 REQUIRED) SET(MAIKO_DISPLAY_X11_DEFINITIONS - "-DXWINDOW -DLOCK_X_UPDATES" + "-DXWINDOW" ) SET(MAIKO_DISPLAY_X11_LIBRARIES X11::X11) SET(MAIKO_DISPLAY_X11_SRCS diff --git a/bin/makefile-cygwin.x86_64-x b/bin/makefile-cygwin.x86_64-x index 8129feb..f280cba 100644 --- a/bin/makefile-cygwin.x86_64-x +++ b/bin/makefile-cygwin.x86_64-x @@ -14,7 +14,7 @@ XFILES = $(OBJECTDIR)xmkicon.o \ $(OBJECTDIR)xwinman.o -XFLAGS = -DXWINDOW -DLOCK_X_UPDATES +XFLAGS = -DXWINDOW # OPTFLAGS is normally -O2. OPTFLAGS = -O2 -g3 diff --git a/bin/makefile-darwin.386-x b/bin/makefile-darwin.386-x index 5125737..abd20e8 100644 --- a/bin/makefile-darwin.386-x +++ b/bin/makefile-darwin.386-x @@ -13,13 +13,13 @@ XFILES = $(OBJECTDIR)xmkicon.o \ $(OBJECTDIR)xwinman.o -XFLAGS = -I/opt/X11/include -DXWINDOW -DLOCK_X_UPDATES +XFLAGS = -I/opt/X11/include -DXWINDOW # OPTFLAGS is normally -O2. OPTFLAGS = -O2 -g DEBUGFLAGS = # -DDEBUG -DOPTRACE DFLAGS = $(DEBUGFLAGS) $(XFLAGS) \ - -DRELEASE=351 -DSTACKCHECK -DFSBCHECK -DPCTRACE + -DRELEASE=351 # -DSTACKCHECK -DFSBCHECK -DPCTRACE LDFLAGS = -L/opt/X11/lib -lX11 -lm LDELDFLAGS = -L/opt/X11/lib -lX11 -lm diff --git a/bin/makefile-darwin.aarch64-x b/bin/makefile-darwin.aarch64-x index f8f59e7..a92219f 100644 --- a/bin/makefile-darwin.aarch64-x +++ b/bin/makefile-darwin.aarch64-x @@ -13,7 +13,7 @@ XFILES = $(OBJECTDIR)xmkicon.o \ $(OBJECTDIR)xwinman.o -XFLAGS = -I/opt/X11/include -DXWINDOW -DLOCK_X_UPDATES +XFLAGS = -I/opt/X11/include -DXWINDOW # OPTFLAGS is normally -O2. OPTFLAGS = -O2 diff --git a/bin/makefile-darwin.ppc-x b/bin/makefile-darwin.ppc-x index 8d35749..50db58f 100644 --- a/bin/makefile-darwin.ppc-x +++ b/bin/makefile-darwin.ppc-x @@ -13,7 +13,7 @@ XFILES = $(OBJECTDIR)xmkicon.o \ $(OBJECTDIR)xwinman.o -XFLAGS = -I/usr/X11/include -DXWINDOW -DLOCK_X_UPDATES +XFLAGS = -I/usr/X11/include -DXWINDOW # OPTFLAGS is normally -O2. OPTFLAGS = -O2 -g diff --git a/bin/makefile-darwin.x86_64-x b/bin/makefile-darwin.x86_64-x index 0ac392b..e17f10b 100644 --- a/bin/makefile-darwin.x86_64-x +++ b/bin/makefile-darwin.x86_64-x @@ -13,7 +13,7 @@ XFILES = $(OBJECTDIR)xmkicon.o \ $(OBJECTDIR)xwinman.o -XFLAGS = -I/opt/X11/include -DXWINDOW -DLOCK_X_UPDATES +XFLAGS = -I/opt/X11/include -DXWINDOW # OPTFLAGS is normally -O2. OPTFLAGS = -O1 -g diff --git a/bin/makefile-freebsd.386-x b/bin/makefile-freebsd.386-x index 69c113b..fa98c63 100644 --- a/bin/makefile-freebsd.386-x +++ b/bin/makefile-freebsd.386-x @@ -13,7 +13,7 @@ XFILES = $(OBJECTDIR)xmkicon.o \ $(OBJECTDIR)xwinman.o -XFLAGS = -I/usr/local/include -DXWINDOW -DLOCK_X_UPDATES +XFLAGS = -I/usr/local/include -DXWINDOW # OPTFLAGS is normally -O2. OPTFLAGS = -O2 -g diff --git a/bin/makefile-freebsd.aarch64-x b/bin/makefile-freebsd.aarch64-x index 6e263f8..7318c9a 100644 --- a/bin/makefile-freebsd.aarch64-x +++ b/bin/makefile-freebsd.aarch64-x @@ -13,7 +13,7 @@ XFILES = $(OBJECTDIR)xmkicon.o \ $(OBJECTDIR)xwinman.o -XFLAGS = -I/usr/local/include -DXWINDOW -DLOCK_X_UPDATES +XFLAGS = -I/usr/local/include -DXWINDOW # OPTFLAGS is normally -O2. OPTFLAGS = -O2 -g diff --git a/bin/makefile-freebsd.x86_64-x b/bin/makefile-freebsd.x86_64-x index 208bc2e..223ba40 100644 --- a/bin/makefile-freebsd.x86_64-x +++ b/bin/makefile-freebsd.x86_64-x @@ -13,7 +13,7 @@ XFILES = $(OBJECTDIR)xmkicon.o \ $(OBJECTDIR)xwinman.o -XFLAGS = -I/usr/local/include -DXWINDOW -DLOCK_X_UPDATES +XFLAGS = -I/usr/local/include -DXWINDOW # OPTFLAGS is normally -O2. OPTFLAGS = -O2 -g diff --git a/bin/makefile-init-darwin.386 b/bin/makefile-init-darwin.386 index fbd168d..c7aaa62 100644 --- a/bin/makefile-init-darwin.386 +++ b/bin/makefile-init-darwin.386 @@ -13,7 +13,7 @@ XFILES = $(OBJECTDIR)xmkicon.o \ $(OBJECTDIR)xwinman.o -XFLAGS = -I/opt/X11/include -DXWINDOW -DLOCK_X_UPDATES +XFLAGS = -I/opt/X11/include -DXWINDOW # OPTFLAGS is normally -O2, for INIT we want unoptimized in case we need to debug it OPTFLAGS = -O0 -g diff --git a/bin/makefile-init-darwin.aarch64 b/bin/makefile-init-darwin.aarch64 index c81744d..1314d4f 100644 --- a/bin/makefile-init-darwin.aarch64 +++ b/bin/makefile-init-darwin.aarch64 @@ -13,7 +13,7 @@ XFILES = $(OBJECTDIR)xmkicon.o \ $(OBJECTDIR)xwinman.o -XFLAGS = -I/opt/X11/include -DXWINDOW -DLOCK_X_UPDATES +XFLAGS = -I/opt/X11/include -DXWINDOW # OPTFLAGS is normally -O2. OPTFLAGS = -O0 -g3 diff --git a/bin/makefile-init-darwin.x86_64 b/bin/makefile-init-darwin.x86_64 index 943e903..322b4a8 100644 --- a/bin/makefile-init-darwin.x86_64 +++ b/bin/makefile-init-darwin.x86_64 @@ -13,7 +13,7 @@ XFILES = $(OBJECTDIR)xmkicon.o \ $(OBJECTDIR)xwinman.o -XFLAGS = -I/opt/X11/include -DXWINDOW -DLOCK_X_UPDATES +XFLAGS = -I/opt/X11/include -DXWINDOW # OPTFLAGS is normally -O2. OPTFLAGS = -O0 -g diff --git a/bin/makefile-init-freebsd.386 b/bin/makefile-init-freebsd.386 index 43ef0f6..ffb691b 100644 --- a/bin/makefile-init-freebsd.386 +++ b/bin/makefile-init-freebsd.386 @@ -13,7 +13,7 @@ XFILES = $(OBJECTDIR)xmkicon.o \ $(OBJECTDIR)xwinman.o -XFLAGS = -I/usr/local/include -DXWINDOW -DLOCK_X_UPDATES +XFLAGS = -I/usr/local/include -DXWINDOW # OPTFLAGS is normally -O0 for init OPTFLAGS = -O0 -g diff --git a/bin/makefile-init-freebsd.aarch64 b/bin/makefile-init-freebsd.aarch64 index e39644c..be70868 100644 --- a/bin/makefile-init-freebsd.aarch64 +++ b/bin/makefile-init-freebsd.aarch64 @@ -13,7 +13,7 @@ XFILES = $(OBJECTDIR)xmkicon.o \ $(OBJECTDIR)xwinman.o -XFLAGS = -I/usr/local/include -DXWINDOW -DLOCK_X_UPDATES +XFLAGS = -I/usr/local/include -DXWINDOW # OPTFLAGS is normally -O0 for init OPTFLAGS = -O0 -g diff --git a/bin/makefile-init-freebsd.x86_64 b/bin/makefile-init-freebsd.x86_64 index 2c3d9ce..8da5044 100644 --- a/bin/makefile-init-freebsd.x86_64 +++ b/bin/makefile-init-freebsd.x86_64 @@ -13,7 +13,7 @@ XFILES = $(OBJECTDIR)xmkicon.o \ $(OBJECTDIR)xwinman.o -XFLAGS = -I/usr/local/include -DXWINDOW -DLOCK_X_UPDATES +XFLAGS = -I/usr/local/include -DXWINDOW # OPTFLAGS is normally -O0 for init OPTFLAGS = -O0 -g diff --git a/bin/makefile-init-linux.x86_64 b/bin/makefile-init-linux.x86_64 index 3f64a50..8d696dd 100644 --- a/bin/makefile-init-linux.x86_64 +++ b/bin/makefile-init-linux.x86_64 @@ -14,7 +14,7 @@ XFILES = $(OBJECTDIR)xmkicon.o \ $(OBJECTDIR)xwinman.o -XFLAGS = -DXWINDOW -DLOCK_X_UPDATES +XFLAGS = -DXWINDOW # OPTFLAGS is normally -O2, for INIT we want unoptimized in case we need to debug it OPTFLAGS = -O0 -g diff --git a/bin/makefile-init-sunos5.sparc b/bin/makefile-init-sunos5.sparc index 69f8997..b75871b 100644 --- a/bin/makefile-init-sunos5.sparc +++ b/bin/makefile-init-sunos5.sparc @@ -30,7 +30,7 @@ XFILES = $(OBJECTDIR)xmkicon.o \ $(OBJECTDIR)xrdopt.o \ $(OBJECTDIR)xwinman.o -XFLAGS = -DXWINDOW -DLOCK_X_UPDATES +XFLAGS = -DXWINDOW # OPTFLAGS is normally -g for MAKEINIT, as it needs debugging often. OPTFLAGS = -g3 -O0 @@ -41,7 +41,7 @@ OPTFLAGS = -g3 -O0 DEBUGFLAGS = # -DSTACKCHECK -DFNSTKCHECK -MACHINEFLAGS = -DOS5 -DUSE_DLPI -DLOCK_X_UPDATES +MACHINEFLAGS = -DOS5 -DUSE_DLPI # The LDEINIT wants to have NOVERSION set, so we don't hang up on # any change-over in versions. diff --git a/bin/makefile-linux.386-x b/bin/makefile-linux.386-x index 37fb185..b25198d 100644 --- a/bin/makefile-linux.386-x +++ b/bin/makefile-linux.386-x @@ -13,7 +13,7 @@ XFILES = $(OBJECTDIR)xmkicon.o \ $(OBJECTDIR)xwinman.o -XFLAGS = -DXWINDOW -DLOCK_X_UPDATES +XFLAGS = -DXWINDOW # OPTFLAGS is normally -O2. OPTFLAGS = -O2 -g3 diff --git a/bin/makefile-linux.aarch64-x b/bin/makefile-linux.aarch64-x index c6db5f1..1f2f156 100644 --- a/bin/makefile-linux.aarch64-x +++ b/bin/makefile-linux.aarch64-x @@ -13,7 +13,7 @@ XFILES = $(OBJECTDIR)xmkicon.o \ $(OBJECTDIR)xrdopt.o \ $(OBJECTDIR)xwinman.o -XFLAGS = -DXWINDOW -DLOCK_X_UPDATES +XFLAGS = -DXWINDOW # OPTFLAGS is normally -O2. OPTFLAGS = -O2 -g3 diff --git a/bin/makefile-linux.armv7l-x b/bin/makefile-linux.armv7l-x index c6db5f1..1f2f156 100644 --- a/bin/makefile-linux.armv7l-x +++ b/bin/makefile-linux.armv7l-x @@ -13,7 +13,7 @@ XFILES = $(OBJECTDIR)xmkicon.o \ $(OBJECTDIR)xrdopt.o \ $(OBJECTDIR)xwinman.o -XFLAGS = -DXWINDOW -DLOCK_X_UPDATES +XFLAGS = -DXWINDOW # OPTFLAGS is normally -O2. OPTFLAGS = -O2 -g3 diff --git a/bin/makefile-linux.x86_64-x b/bin/makefile-linux.x86_64-x index 8129feb..f280cba 100644 --- a/bin/makefile-linux.x86_64-x +++ b/bin/makefile-linux.x86_64-x @@ -14,7 +14,7 @@ XFILES = $(OBJECTDIR)xmkicon.o \ $(OBJECTDIR)xwinman.o -XFLAGS = -DXWINDOW -DLOCK_X_UPDATES +XFLAGS = -DXWINDOW # OPTFLAGS is normally -O2. OPTFLAGS = -O2 -g3 diff --git a/bin/makefile-openbsd.x86_64-x b/bin/makefile-openbsd.x86_64-x index 70a1798..b95e5f5 100644 --- a/bin/makefile-openbsd.x86_64-x +++ b/bin/makefile-openbsd.x86_64-x @@ -13,7 +13,7 @@ XFILES = $(OBJECTDIR)xmkicon.o \ $(OBJECTDIR)xwinman.o -XFLAGS = -I/usr/X11R6/include -DXWINDOW -DLOCK_X_UPDATES +XFLAGS = -I/usr/X11R6/include -DXWINDOW # OPTFLAGS is normally -O2. OPTFLAGS = -O2 -g3 diff --git a/bin/makefile-sunos5.386-x b/bin/makefile-sunos5.386-x index f1c7b78..22bedc6 100644 --- a/bin/makefile-sunos5.386-x +++ b/bin/makefile-sunos5.386-x @@ -22,7 +22,7 @@ XFILES = $(OBJECTDIR)xmkicon.o \ $(OBJECTDIR)xrdopt.o \ $(OBJECTDIR)xwinman.o -XFLAGS = -DXWINDOW -DLOCK_X_UPDATES +XFLAGS = -DXWINDOW # OPTFLAGS is normally -O2. OPTFLAGS = -O2 -g @@ -36,7 +36,6 @@ DEBUGFLAGS = # -DSTACKCHECK -DFNSTKCHECK DFLAGS = $(XFLAGS) \ $(DEBUGFLAGS) \ -DOS5 \ - -DLOCK_X_UPDATES \ -DRELEASE=351 LDFLAGS = -L/usr/X11/lib -lX11 -lc -lm -lsocket -lnsl diff --git a/bin/makefile-sunos5.i386-x b/bin/makefile-sunos5.i386-x index 8831073..40005ea 100644 --- a/bin/makefile-sunos5.i386-x +++ b/bin/makefile-sunos5.i386-x @@ -22,7 +22,7 @@ XFILES = $(OBJECTDIR)xmkicon.o \ $(OBJECTDIR)xrdopt.o \ $(OBJECTDIR)xwinman.o -XFLAGS = -DXWINDOW -DLOCK_X_UPDATES +XFLAGS = -DXWINDOW # OPTFLAGS is normally -O2. OPTFLAGS = -O2 -g3 @@ -36,7 +36,6 @@ DEBUGFLAGS = # -DSTACKCHECK -DFNSTKCHECK DFLAGS = $(XFLAGS) \ $(DEBUGFLAGS) \ -DOS5 -DUSE_DLPI \ - -DLOCK_X_UPDATES \ -I$(OPENWINHOME)/include \ -DRELEASE=210 diff --git a/bin/makefile-sunos5.sparc-x b/bin/makefile-sunos5.sparc-x index a9304cc..cca4965 100644 --- a/bin/makefile-sunos5.sparc-x +++ b/bin/makefile-sunos5.sparc-x @@ -29,7 +29,7 @@ XFILES = $(OBJECTDIR)xmkicon.o \ $(OBJECTDIR)xrdopt.o \ $(OBJECTDIR)xwinman.o -XFLAGS = -DXWINDOW -DLOCK_X_UPDATES +XFLAGS = -DXWINDOW # OPTFLAGS is normally -O2. OPTFLAGS = -O2 -g3 @@ -40,7 +40,7 @@ OPTFLAGS = -O2 -g3 DEBUGFLAGS = # -DSTACKCHECK -DFNSTKCHECK -MACHINEFLAGS = -DOS5 -DUSE_DLPI -DLOCK_X_UPDATES +MACHINEFLAGS = -DOS5 -DUSE_DLPI DFLAGS = $(XFLAGS) \ $(DEBUGFLAGS) \ diff --git a/bin/makefile-sunos5.x86_64-x b/bin/makefile-sunos5.x86_64-x index 3f8ab9f..8322b1b 100644 --- a/bin/makefile-sunos5.x86_64-x +++ b/bin/makefile-sunos5.x86_64-x @@ -22,7 +22,7 @@ XFILES = $(OBJECTDIR)xmkicon.o \ $(OBJECTDIR)xrdopt.o \ $(OBJECTDIR)xwinman.o -XFLAGS = -DXWINDOW -DLOCK_X_UPDATES +XFLAGS = -DXWINDOW # OPTFLAGS is normally -O2. OPTFLAGS = -O2 -g @@ -36,7 +36,6 @@ DEBUGFLAGS = # -DSTACKCHECK -DFNSTKCHECK DFLAGS = $(XFLAGS) \ $(DEBUGFLAGS) \ -DOS5 \ - -DLOCK_X_UPDATES \ -DUSE_DLPI \ -DRELEASE=351 diff --git a/inc/keyeventdefs.h b/inc/keyeventdefs.h index 69e69c3..b805988 100644 --- a/inc/keyeventdefs.h +++ b/inc/keyeventdefs.h @@ -1,7 +1,7 @@ #ifndef KEYEVENTDEFS_H #define KEYEVENTDEFS_H 1 #include -void getsignaldata(int sig); +void process_io_events(); void kb_trans(u_short keycode, u_short upflg); void taking_mouse_down(void); void copy_cursor(int newx, int newy); diff --git a/inc/version.h b/inc/version.h index 869a2fa..63e883c 100644 --- a/inc/version.h +++ b/inc/version.h @@ -223,7 +223,6 @@ error Must specify RELEASE to build Medley. #ifdef OS5 /* Solaris, sort of SYSV-ish, but not really */ #define MAIKO_ENABLE_ETHERNET -#define LOCK_X_UPDATES 1 #endif /* OS5 */ diff --git a/inc/xwinmandefs.h b/inc/xwinmandefs.h index 4729897..b1ee029 100644 --- a/inc/xwinmandefs.h +++ b/inc/xwinmandefs.h @@ -8,5 +8,5 @@ void Set_BitGravity(XButtonEvent *event, DspInterface dsp, Window window, int gr void enable_Xkeyboard(DspInterface dsp); void disable_Xkeyboard(DspInterface dsp); void beep_Xkeyboard(DspInterface dsp); -void getXsignaldata(DspInterface dsp); +void process_Xevents(DspInterface dsp); #endif diff --git a/src/keyevent.c b/src/keyevent.c index 77e0eac..c7738ff 100644 --- a/src/keyevent.c +++ b/src/keyevent.c @@ -133,10 +133,6 @@ extern DLword *DisplayRegion68k; static struct timeval SelectTimeout = {0, 0}; #endif /* DOS */ -#ifdef XWINDOW -extern volatile sig_atomic_t Event_Req; -#endif /* XWINDOW */ - extern MISCSTATS *MiscStats; LispPTR *LASTUSERACTION68k; LispPTR *CLastUserActionCell68k; @@ -187,7 +183,7 @@ LispPTR *MOUSECHORDTICKS68k; /**NEW GLOBAL***-> will be moved***/ LispPTR *KEYBOARDEVENTQUEUE68k; LispPTR *KEYBUFFERING68k; -int KBDEventFlg = NIL; +int KBDEventFlg = 0; DLword *CTopKeyevent; LispPTR DOBUFFEREDTRANSITION_index; @@ -213,20 +209,12 @@ DLword ColorCursor_savebitmap[CURSORWIDTH / COLORPIXELS_IN_DLWORD * CURSORHEIGHT /************************************************************************/ /* */ -/* G E T S I G N A L D A T A */ -/* */ -/* Handler for the SIGIO interrupt, which happens */ -/* 1. When a key transition happens */ -/* 2. On mouse moves */ -/* 3. When TCP input becomes available. */ -/* 4. When a NIT ethernet packet becomes available. */ -/* 5. When a console/log/stderr msg needs to be printed. */ -/* */ -/* */ -/* */ -/* */ -/* */ +/* p r o c e s s _ i o _ e v e n t s */ /* */ +/* Periodically, or After a SIGIO interrupt which happens */ +/* 1. When TCP input becomes available. */ +/* 2. When a NIT ethernet packet becomes available. */ +/* 3. When a console/log/stderr msg needs to be printed. */ /* */ /* */ /* Statics: LispReadFds A 32-bit vector with a 1 for each */ @@ -256,49 +244,16 @@ DLword ColorCursor_savebitmap[CURSORWIDTH / COLORPIXELS_IN_DLWORD * CURSORHEIGHT /* */ /************************************************************************/ -void getsignaldata(int sig) +void process_io_events() { #ifndef DOS - fd_set rfds, efds; + fd_set rfds; u_int iflags; int i; -#ifdef XWINDOW -#if defined(sun) - if (Event_Req) { - if (!XLocked++) - getXsignaldata(currentdsp); - else - XNeedSignal = 1; - Event_Req = FALSE; - XLocked--; - } -#endif -#endif /* XWINDOW */ - - /* #ifndef KBINT */ - /* FD_COPY would be preferred but uses deprecated bcopy() on macOS. Why? */ memcpy(&rfds, &LispReadFds, sizeof(rfds)); - memcpy(&efds, &LispReadFds, sizeof(efds)); -/* label and ifs not needed if only keyboard on SIGIO */ -getmore: - if (select(32, &rfds, NULL, &efds, &SelectTimeout) >= 0) - { - /* need to print out fd sets... - DBPRINT(("SIGIO: fd mask(r/e) = 0x%x/0x%x.\n", rfds, efds)); - */ - - -#ifdef XWINDOW - if (FD_ISSET(ConnectionNumber(currentdsp->display_id), &rfds)) { - if (!XLocked) - getXsignaldata(currentdsp); - else - XNeedSignal = 1; - } - -#endif /* XWINDOW */ + if (select(32, &rfds, NULL, NULL, &SelectTimeout) > 0) { #ifdef MAIKO_ENABLE_ETHERNET if (ether_fd >= 0 && FD_ISSET(ether_fd, &rfds)) { /* Raw ethernet (NIT) I/O happened, so handle it. */ @@ -338,7 +293,7 @@ getmore: } /* #endif */ #endif /* DOS */ -} /* end getsignaldata */ +} /* end process_io_events */ /************************************************************************/ diff --git a/src/rs232c.c b/src/rs232c.c index 0ceb13e..389e8a2 100644 --- a/src/rs232c.c +++ b/src/rs232c.c @@ -253,7 +253,7 @@ rs232c_read() { } } else { /* - * SIGIO handler getsignaldata and the successive + * SIGIO handler, process_io_events, and the successive * rs232c_read has been called before Lisp prepares * the next buffer. Turn on RS232C_remain_data to * specify to read the remaining data after. diff --git a/src/timer.c b/src/timer.c index 7ae3132..5227c6a 100644 --- a/src/timer.c +++ b/src/timer.c @@ -87,9 +87,7 @@ extern DspInterface currentdsp; int TIMEOUT_TIME; /* For file system timeout */ -#ifdef XWINDOW -volatile sig_atomic_t Event_Req = FALSE; -#endif /* XWINDOW */ +volatile sig_atomic_t IO_Signalled = FALSE; static int gettime(int casep); @@ -403,7 +401,7 @@ void update_timer() { /* TIMER_INTERVAL usec ~ 20 per second. This should live in some machine-configuration file somewhere - it can be changed as the -t parameter to lisp*/ -int TIMER_INTERVAL = 25000; +int TIMER_INTERVAL = 10000; extern int LispWindowFd; @@ -423,10 +421,6 @@ static void int_timer_service(int sig) Irq_Stk_Check = 0; Irq_Stk_End = 0; - -#ifdef XWINDOW - Event_Req = TRUE; -#endif } /************************************************************************/ @@ -466,7 +460,7 @@ static void int_timer_init() timer_action.sa_handler = int_timer_service; sigemptyset(&timer_action.sa_mask); - timer_action.sa_flags = 0; + timer_action.sa_flags = SA_RESTART; if (sigaction(SIGVTALRM, &timer_action, NULL) == -1) { perror("sigaction: SIGVTALRM"); @@ -496,15 +490,10 @@ void int_io_open(int fd) { #ifdef DOS /* would turn on DOS kbd signal handler here */ -#elif KBINT - +#elseif defined(O_ASYNC) DBPRINT(("int_io_opening %d\n", fd)); - if (fcntl(fd, F_SETOWN, getpid()) == -1) { -#ifdef DEBUG - perror("fcntl F_SETOWN ERROR"); -#endif - }; - if (fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) | O_ASYNC) == -1) perror("fcntl F_SETFL error"); + if (fcntl(fd, F_SETOWN, getpid()) == -1) perror("fcntl F_SETOWN error"); + if (fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) | O_ASYNC) == -1) perror("fcntl F_SETFL on error"); #endif } @@ -512,11 +501,27 @@ void int_io_close(int fd) { #ifdef DOS /* Turn off signaller here */ -#elif KBINT - fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) & ~O_ASYNC); +#elseif defined(O_ASYNC) + if (fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) & ~O_ASYNC) == -1) perror("fcntl_F_SETFL off error"); #endif } +/************************************************************************/ +/* */ +/* i n t _ i o _ s e r v i c e */ +/* */ +/* Handle SIGIO */ +/* */ +/* */ +/************************************************************************/ + +static void int_io_service(int sig) +{ + Irq_Stk_Check = 0; + Irq_Stk_End = 0; + IO_Signalled = TRUE; +} + /************************************************************************/ /* */ /* i n t _ i o _ i n i t */ @@ -531,7 +536,7 @@ void int_io_close(int fd) static void int_io_init() { #ifndef DOS struct sigaction io_action; - io_action.sa_handler = getsignaldata; + io_action.sa_handler = int_io_service; sigemptyset(&io_action.sa_mask); io_action.sa_flags = 0; @@ -541,11 +546,6 @@ static void int_io_init() { DBPRINT(("I/O interrupts enabled\n")); } -#if defined(XWINDOW) && defined(I_SETSIG) - if (ioctl(ConnectionNumber(currentdsp->display_id), I_SETSIG, S_INPUT) < 0) - perror("ioctl on X fd - SETSIG for input handling failed"); -#endif - #if defined(USE_DLPI) DBPRINT(("INIT ETHER: Doing I_SETSIG.\n")); if (ether_fd > 0) diff --git a/src/xc.c b/src/xc.c index 8370243..c664c1a 100644 --- a/src/xc.c +++ b/src/xc.c @@ -99,6 +99,7 @@ #include "ubf3defs.h" #include "unwinddefs.h" #include "vars3defs.h" +#include "xwinmandefs.h" #include "z2defs.h" #ifdef DOS @@ -108,6 +109,8 @@ extern IOPAGE *IOPage68K; extern KbdInterface currentkbd; extern DspInterface currentdsp; extern MouseInterface currentmouse; +#else +extern DspInterface currentdsp; #endif /* DOS */ typedef struct conspage ConsPage; @@ -141,11 +144,8 @@ register LispPTR tscache asm("bx"); #define PVARL PVar #define IVARL IVar -#ifdef XWINDOW -extern volatile sig_atomic_t Event_Req; /* != 0 when it's time to check X events - on machines that don't get them reliably - (e.g. Suns running OpenWindows) */ -#endif /* XWINDOW */ +/* used by SIGIO signal handler to indicate I/O may be possible */ +extern volatile sig_atomic_t IO_Signalled; #ifdef PCTRACE /* For keeping a trace table (ring buffer) of 100 last PCs */ @@ -1112,17 +1112,22 @@ check_interrupt: Irq_Stk_End = (UNSIGNED)EndSTKP; } - /* Check for an IRQ request */ + /* This is a good time to process keyboard/mouse and ethernet I/O + * X events are not managed in the async/SIGIO code while + * raw ethernet, serial port, and socket connections are. + * If the system is configured with SIGIO handling we have a hint + * that allows us to cheaply skip if there's nothing to do + */ + process_Xevents(currentdsp); + + if (IO_Signalled) { + IO_Signalled = FALSE; + process_io_events(); + } if ((Irq_Stk_End <= 0) || (Irq_Stk_Check <= 0) || need_irq) { if (StkOffset_from_68K(CSTKPTR) > InterfacePage->stackbase) { /* Interrupts not Disabled */ - /* XXX: what on earth is this code trying to accomplish by calling - getsignaldata - */ -#if !defined(KBINT) || defined(OS4) - getsignaldata(0); -#endif EXT; update_timer(); diff --git a/src/xinit.c b/src/xinit.c index d47c8d9..9d7d17b 100644 --- a/src/xinit.c +++ b/src/xinit.c @@ -30,6 +30,7 @@ #include "adr68k.h" #include "xinitdefs.h" #include "dspifdefs.h" +#include "timerdefs.h" #include "xbbtdefs.h" #include "xlspwindefs.h" #include "xwinmandefs.h" @@ -65,7 +66,6 @@ Colormap Colors; volatile sig_atomic_t XLocked = 0; /* non-zero while doing X ops, to avoid signals */ volatile sig_atomic_t XNeedSignal = 0; /* T if an X interrupt happened while XLOCK asserted */ -extern fd_set LispReadFds; /************************************************************************/ /* */ @@ -108,10 +108,6 @@ void lisp_Xexit(DspInterface dsp) { assert(Lisp_Xinitialized); -#if defined(I_SETSIG) - ioctl(ConnectionNumber(dsp->display_id), I_SETSIG, 0); /* so no interrupts happen during */ -#endif - XLOCK; XDestroySubwindows(dsp->display_id, dsp->LispWindow); XDestroyWindow(dsp->display_id, dsp->LispWindow); @@ -180,9 +176,6 @@ void Open_Display(DspInterface dsp) { assert(Lisp_Xinitialized == false); - FD_SET(ConnectionNumber(dsp->display_id), &LispReadFds); - fcntl(ConnectionNumber(dsp->display_id), F_SETOWN, getpid()); - /****************************************************/ /* If debugging, set the X connection so that */ /* we run synchronized--so a debugger can */ @@ -200,7 +193,7 @@ void Open_Display(DspInterface dsp) Create_LispWindow(dsp); /* Make the main window */ Lisp_Xinitialized = true; - init_Xevent(dsp); /* Turn on the intrpts. */ + init_Xevent(dsp); /* Turn on the event reporting */ } /* end OpenDisplay */ /*********************************************************************/ diff --git a/src/xlspwin.c b/src/xlspwin.c index 55dddde..f4cc2b6 100644 --- a/src/xlspwin.c +++ b/src/xlspwin.c @@ -340,8 +340,8 @@ void DoRing() { KBEVENT *kbevent; TPRINT(("TRACE: DoRing()\n")); - do_ring: + /* DEL is not generally present on a Mac X keyboard, Ctrl-shift-ESC would be 18496 */ if (((*EmKbdAd268K) & 2113) == 0) { /*Ctrl-shift-NEXT*/ error("****** EMERGENCY Interrupt ******"); *EmKbdAd268K = KB_ALLUP; /*reset*/ diff --git a/src/xwinman.c b/src/xwinman.c index 39965b9..c88c29d 100644 --- a/src/xwinman.c +++ b/src/xwinman.c @@ -171,7 +171,7 @@ void beep_Xkeyboard(DspInterface dsp) /************************************************************************/ /* */ -/* g e t X s i g n a l d a t a */ +/* p r o c e s s _ X e v e n t s */ /* */ /* Take X key/mouse events and turn them into Lisp events */ /* */ @@ -179,7 +179,7 @@ void beep_Xkeyboard(DspInterface dsp) extern int Current_Hot_X, Current_Hot_Y; /* Cursor hotspot */ -void getXsignaldata(DspInterface dsp) +void process_Xevents(DspInterface dsp) { XEvent report; @@ -193,8 +193,6 @@ void getXsignaldata(DspInterface dsp) (short)((report.xmotion.x + dsp->Visible.x) & 0xFFFF) - Current_Hot_X; *EmCursorY68K = (*((DLword *)EmMouseY68K)) = (short)((report.xmotion.y + dsp->Visible.y) & 0xFFFF) - Current_Hot_Y; - DoRing(); - if ((KBDEventFlg) > 0) Irq_Stk_End = Irq_Stk_Check = 0; break; case KeyPress: kb_trans(SUNLispKeyMap[(report.xkey.keycode) - KEYCODE_OFFSET], FALSE); @@ -342,4 +340,4 @@ void getXsignaldata(DspInterface dsp) Set_BitGravity(&report.xbutton, dsp, dsp->NWGrav, NorthWestGravity); XFlush(dsp->display_id); } /* end while */ -} /* end getXsignaldata() */ +} /* end process_Xevents */