public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-7636] [PATCH] PR modula2/108344 disable default opening of /dev/tty
@ 2023-07-28 21:51 Gaius Mulley
0 siblings, 0 replies; only message in thread
From: Gaius Mulley @ 2023-07-28 21:51 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:35a04220554d62d9bbe068dfa2f52d4d2d572805
commit r13-7636-g35a04220554d62d9bbe068dfa2f52d4d2d572805
Author: Gaius Mulley <gaiusmod2@gmail.com>
Date: Fri Jul 28 22:50:41 2023 +0100
[PATCH] PR modula2/108344 disable default opening of /dev/tty
This patch changes removes the static initialisation code for
KeyBoardLEDs.cc. The module is only initialised if one of the
exported functions is called. This is useful as the module will
access /dev/tty which might not be available. TimerHandler.mod has
also been changed to disable the scroll lock LED as a sign of life.
gcc/m2/ChangeLog:
PR modula2/108344
* gm2-libs-coroutines/TimerHandler.mod (EnableLED): New
constant.
(Timer): Test EnableLED before switching on the scroll LED.
libgm2/ChangeLog:
PR modula2/108344
* libm2cor/KeyBoardLEDs.cc (initialize_module): New
function.
(SwitchScroll): Call initialize_module.
(SwitchNum): Call initialize_module.
(SwitchCaps): Call initialize_module.
(SwitchLEDs): Call initialize_module.
(M2EXPORT): Remove initialization code.
(cherry picked from commit cf4dcfa6727b89362494bd49e2a28ebd10d767ce)
Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
Diff:
---
gcc/m2/gm2-libs-coroutines/TimerHandler.mod | 37 ++++++++++++++++-------------
libgm2/libm2cor/KeyBoardLEDs.cc | 31 ++++++++++++++++--------
2 files changed, 41 insertions(+), 27 deletions(-)
diff --git a/gcc/m2/gm2-libs-coroutines/TimerHandler.mod b/gcc/m2/gm2-libs-coroutines/TimerHandler.mod
index d3dee319ca1..1285873486d 100644
--- a/gcc/m2/gm2-libs-coroutines/TimerHandler.mod
+++ b/gcc/m2/gm2-libs-coroutines/TimerHandler.mod
@@ -41,8 +41,9 @@ CONST
MaxQuantum = 4 ; (* Maximum ticks a process may consume *)
(* before being rescheduled. *)
BaseTicks = 1000000 ; (* Max resolution of clock ticks per sec *)
- TimerStackSize = 100000H ; (* Reasonable sized stack for a process *)
- Debugging = FALSE ; (* Do you want lots of debugging info? *)
+ TimerStackSize = 100000H ; (* Reasonable sized stack for a process *)
+ Debugging = FALSE ; (* Do you want lots of debugging info? *)
+ EnableLED = FALSE ; (* Should the scroll LED be pulsed? *)
TYPE
EVENT = POINTER TO RECORD
@@ -328,21 +329,23 @@ BEGIN
(* Now compenstate for lost ticks *)
StartClock (TimerIntNo, CurrentCount + (BaseTicks DIV TicksPerSecond)) ;
- (* your code needs to go here *)
- INC (TotalTicks) ; (* (iii) *) (* remove for student *)
- (* now pulse scroll LED *) (* remove for student *)
- IF (TotalTicks MOD TicksPerSecond) = 0 (* remove for student *)
- THEN (* remove for student *)
- ScrollLED := NOT ScrollLED ; (* remove for student *)
- (* r := printf("<scroll %d>", TotalTicks); *)
- SwitchScroll(ScrollLED) (* (iv) *) (* remove for student *)
- END ; (* remove for student *)
- IF (TotalTicks MOD MaxQuantum) = 0 (* remove for student *)
- THEN (* remove for student *)
- RotateRunQueue (* (ii) *) (* remove for student *)
- END ; (* remove for student *)
-
- CheckActiveQueue (* (i) *) (* remove for student *)
+ INC (TotalTicks) ; (* (iii) *)
+ IF EnableLED
+ THEN
+ (* now pulse scroll LED *)
+ IF (TotalTicks MOD TicksPerSecond) = 0
+ THEN
+ ScrollLED := NOT ScrollLED ;
+ (* r := printf("<scroll %d>", TotalTicks); *)
+ SwitchScroll(ScrollLED) (* (iv) *)
+ END
+ END ;
+ IF (TotalTicks MOD MaxQuantum) = 0
+ THEN
+ RotateRunQueue (* (ii) *)
+ END ;
+
+ CheckActiveQueue (* (i) *)
END
END Timer ;
diff --git a/libgm2/libm2cor/KeyBoardLEDs.cc b/libgm2/libm2cor/KeyBoardLEDs.cc
index e2e8198fb13..9ecf38941ab 100644
--- a/libgm2/libm2cor/KeyBoardLEDs.cc
+++ b/libgm2/libm2cor/KeyBoardLEDs.cc
@@ -53,10 +53,27 @@ static int fd;
static int initialized = FALSE;
+void
+initialize_module (void)
+{
+ if (! initialized)
+ {
+ initialized = true;
+ fd = open ("/dev/tty", O_RDONLY);
+ if (fd == -1)
+ {
+ perror ("unable to open /dev/tty");
+ exit (1);
+ }
+ }
+}
+
extern "C" void
EXPORT(SwitchScroll) (int scrolllock)
{
unsigned char leds;
+
+ initialize_module ();
int r = ioctl (fd, KDGETLED, &leds);
if (scrolllock)
leds = leds | LED_SCR;
@@ -69,6 +86,8 @@ extern "C" void
EXPORT(SwitchNum) (int numlock)
{
unsigned char leds;
+
+ initialize_module ();
int r = ioctl (fd, KDGETLED, &leds);
if (numlock)
leds = leds | LED_NUM;
@@ -81,6 +100,8 @@ extern "C" void
EXPORT(SwitchCaps) (int capslock)
{
unsigned char leds;
+
+ initialize_module ();
int r = ioctl (fd, KDGETLED, &leds);
if (capslock)
leds = leds | LED_CAP;
@@ -100,16 +121,6 @@ EXPORT(SwitchLeds) (int numlock, int capslock, int scrolllock)
extern "C" void
M2EXPORT(init) (int, char **, char **)
{
- if (! initialized)
- {
- initialized = TRUE;
- fd = open ("/dev/tty", O_RDONLY);
- if (fd == -1)
- {
- perror ("unable to open /dev/tty");
- exit (1);
- }
- }
}
#else
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-07-28 21:51 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-28 21:51 [gcc r13-7636] [PATCH] PR modula2/108344 disable default opening of /dev/tty Gaius Mulley
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).