[AD] delay linux console init

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


Attached is a patch related to this thread: http://www.allegro.cc/forums/view_thread.php?_id=547283 It basically delays Linux console initialization until there is no driver that requires a console and releases the console when no driver is using it any more. This way the user can write command-line programs using timers (and even mouse) without needing a real console.

I couldn't test the SVGA driver because it doesn't work for some reason.


--
Milan Mimica
http://sparklet.sf.net
Index: allegro/include/allegro/platform/aintlnx.h
===================================================================
RCS file: /cvsroot/alleg/allegro/include/allegro/platform/aintlnx.h,v
retrieving revision 1.10
diff -u -3 -p -r1.10 aintlnx.h
--- allegro/include/allegro/platform/aintlnx.h	7 Mar 2005 22:55:24 -0000	1.10
+++ allegro/include/allegro/platform/aintlnx.h	28 Nov 2005 19:47:46 -0000
@@ -148,8 +148,8 @@ extern int __al_linux_got_text_message;
 extern struct termios __al_linux_startup_termio;
 extern struct termios __al_linux_work_termio;
 
-int __al_linux_init_console (void);
-int __al_linux_done_console (void);
+int __al_linux_use_console (void);
+int __al_linux_leave_console (void);
 
 int __al_linux_console_graphics (void);
 int __al_linux_console_text (void);
Index: allegro/src/linux/lconsole.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/linux/lconsole.c,v
retrieving revision 1.10
diff -u -3 -p -r1.10 lconsole.c
--- allegro/src/linux/lconsole.c	7 Feb 2003 12:38:34 -0000	1.10
+++ allegro/src/linux/lconsole.c	28 Nov 2005 19:48:39 -0000
@@ -46,6 +46,7 @@ struct termios __al_linux_startup_termio
 struct termios __al_linux_work_termio;
 
 
+
 /* get_tty:
  *  Compares the inodes of /dev/ttyn (1 <= n <= 24) with the inode of the
  *  passed file, returning whichever it matches, 0 if none, -1 on error.
@@ -71,10 +72,11 @@ static int get_tty (int fd)
    return (tty <= 24) ? tty : 0;
 }
 
-/* __al_linux_init_console:
+
+/* init_console:
  *  Initialises this subsystem.
  */
-int __al_linux_init_console(void)
+int init_console(void)
 {
    char tmp[256];
 
@@ -226,10 +228,11 @@ int __al_linux_init_console(void)
    return 0;
 }
 
-/* __al_linux_done_console
+
+/* done_console
  *  Undo `init_console'.
  */
-int __al_linux_done_console (void)
+int done_console (void)
 {
    char msg[256];
    int ret;
@@ -262,6 +265,38 @@ int __al_linux_done_console (void)
 }
 
 
+static int console_users = 0;
+
+/* __al_linux_use_console:
+ *   Init Linux console if not initialized yet.
+ */
+int __al_linux_use_console(void) {
+   console_users++;
+   if (console_users > 1) return 0;
+
+   if (init_console()) return 1;
+
+   /* Initialise the console switching system */
+   set_display_switch_mode (SWITCH_PAUSE);
+   return __al_linux_init_vtswitch();
+}
+
+
+/* __al_linux_leave_console:
+ *   Close Linux console if no driver uses it any more.
+ */
+int __al_linux_leave_console(void) {
+   ASSERT (console_users > 0);
+   console_users--;
+   if (console_users > 0) return 0;
+
+   /* shut down the console switching system */
+   if (__al_linux_done_vtswitch()) return 1;
+
+   return done_console();
+}
+
+
 static int graphics_mode = 0;
 
 /* __al_linux_console_graphics:
@@ -269,13 +304,17 @@ static int graphics_mode = 0;
  */
 int __al_linux_console_graphics (void)
 {
+   if (__al_linux_use_console()) return 1;
+
    if (graphics_mode) return 0;  /* shouldn't happen */
    ioctl(__al_linux_console_fd, KDSETMODE, KD_GRAPHICS);
    __al_linux_wait_for_display();
    graphics_mode = 1;
+
    return 0;
 }
 
+
 /* __al_linux_console_text:
  *  Returns the console to text mode.
  */
@@ -295,6 +334,9 @@ int __al_linux_console_text (void)
    } while (ret < 10);
 
    graphics_mode = 0;
+   
+   __al_linux_leave_console();
+
    return 0;
 }
 
Index: allegro/src/linux/lkeybd.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/linux/lkeybd.c,v
retrieving revision 1.16
diff -u -3 -p -r1.16 lkeybd.c
--- allegro/src/linux/lkeybd.c	5 Nov 2005 13:24:51 -0000	1.16
+++ allegro/src/linux/lkeybd.c	28 Nov 2005 19:48:40 -0000
@@ -382,6 +382,8 @@ static void resume_keyboard(void)
 
 static int linux_key_init (void)
 {
+        if (__al_linux_use_console()) return 1;
+
         std_keyboard.fd = dup (__al_linux_console_fd);
 
         /* Set terminal attributes we need */
@@ -410,11 +412,13 @@ static int linux_key_init (void)
 
 static void linux_key_exit (void)
 {
-	/* Reset LED mode before exiting */
-	ioctl(std_keyboard.fd, KDSETLED, 8);
+        /* Reset LED mode before exiting */
+        ioctl(std_keyboard.fd, KDSETLED, 8);
 
         __al_linux_remove_standard_driver (&std_keyboard);
         close (std_keyboard.fd);
+
+        __al_linux_leave_console();
 }
 
 static void linux_set_leds (int leds)
Index: allegro/src/linux/lsystem.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/linux/lsystem.c,v
retrieving revision 1.28
diff -u -3 -p -r1.28 lsystem.c
--- allegro/src/linux/lsystem.c	20 Aug 2005 02:45:23 -0000	1.28
+++ allegro/src/linux/lsystem.c	28 Nov 2005 19:48:41 -0000
@@ -184,9 +184,6 @@ static int sys_linux_init (void)
 	/* Load dynamic modules */
 	_unix_load_modules(SYSTEM_LINUX);
     
-	/* Initialise the console subsystem */
-	if (__al_linux_init_console()) return -1;
-
 	/* Initialise VGA helpers */
 #ifdef ALLEGRO_LINUX_VGA
 	if (__al_linux_have_ioperms)
@@ -211,10 +208,6 @@ static int sys_linux_init (void)
 		return -1;
 	}
 
-	/* Initialise the console switching system */
-	set_display_switch_mode (SWITCH_PAUSE);
-	__al_linux_init_vtswitch();
-
 	return 0;
 }
 
@@ -225,9 +218,6 @@ static int sys_linux_init (void)
  */
 static void sys_linux_exit (void)
 {
-	/* shut down the console switching system */
-	__al_linux_done_vtswitch();
-
 	/* shut down asynchronous event processing */
 	__al_linux_bgman_exit();
 
@@ -248,9 +238,6 @@ static void sys_linux_exit (void)
 		__al_linux_shutdown_vga_helpers();
 #endif
 
-	/* shut down the console subsystem */
-	__al_linux_done_console();
-
 	/* unload dynamic modules */
 	_unix_unload_modules();
 
Index: allegro/src/linux/svgalib.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/linux/svgalib.c,v
retrieving revision 1.37
diff -u -3 -p -r1.37 svgalib.c
--- allegro/src/linux/svgalib.c	16 Oct 2004 19:45:32 -0000	1.37
+++ allegro/src/linux/svgalib.c	28 Nov 2005 19:48:41 -0000
@@ -487,6 +487,8 @@ static BITMAP *svga_init(int w, int h, i
       return NULL;
    }
 
+   __al_linux_use_console();
+
    /* Initialise SVGAlib.  */
    if (virgin) {
       if (!svga_version2())
@@ -523,6 +525,7 @@ static void svga_exit(BITMAP *b)
    }
 
    safe_vga_setmode(TEXT, 1);
+   __al_linux_leave_console();
 }
 
 


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/