Re: [AD] d_ctext_proc

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


On 2003-06-30, Vincent <Vincent.Penquerch@xxxxxxxxxx> wrote:
> Since I've been officially admitted in the small circle of
> contributors whose description ends with "too.", I must live up to my
> public image, so here are a bunch of patches.

Welcome to the club!  The best bit is, you can stop contributing and
your description won't get revoked :-)

> umodules:
> > > Modules (in linux/umodules) are loaded 2 times.
> >
> > Could you elaborate a bit? If I put a printf() right after dlopen()
> > in unix/umodules.c, I see only one line per module in module.lst
> > with the main test program.
> 
> This happens only on the Linux console (not under X).  If the system is
> autodetected and nothing is specified in the config file, _xwin_sysdrv_init
> (x/xsystem.c) is called before sys_linux_init (linux/lsystem.c).  It first
> loads the modules and only then tries to open a display, which fails.  Then
> sys_linux_init is called and loads the modules again.

_xwin_sysdrv_exit() seems to be called the right places, which would
unload the modules first.  What am I missing?

[Btw, if anyone wanted a project, they could try making the modules load
on demand, rather than the current system which loads them all when the
system driver is initialised (wasteful, as half or more of the drivers
will probably go unused during the program).  One easy-ish way would be
to write stub drivers which load the real driver when the init method is
called, then modifies its own vtable to point to methods from the real
driver, then unloads the real driver when the exit method is called.
The stub drivers would be loaded once using the umodules.c subsystem.
But I'm dreaming if I think anyone will do this :-) ]

> Yet some other bugs:
> In linux/lsystem.c, __al_linux_shutdown_vga_helpers is called even when the
> corresponding init hasn't been done.  Fixed in the attached patch
> (vga_helpers.diff)

Will commit, with an additional pedantic check for info->data == NULL in
__al_linux_shutdown_vga_helpers().

> The function update_mouse (in src/linux/lmouse.c, not the one in
> src/mouse.c)
> is called both on SIGALRM (from __al_linux_update_standard_drivers, in
> src/linux/lstddrv.c) and on SIGIO (from async_io_event, in
> src/linux/lasyncio.c). (I'm still not using pthread :).  update_mouse isn't
> reentrant, and on very heavy loads it fills up the memory with trash.
> I can't understand if it's possible to disable one of the two update
> methods,
> so I've attempted to lock the code that fill the buffer (see the patch
> update_mouse.diff).

*Oops*  I've wanted to kill off lasyncio.c for a long time.  I wasn't
sure if it was still needed after bg_man, but everything seemed to work
okay (I don't know how!) so I didn't spend much time trying to figure it
out.  "You're in a maze of twisty little functions, all similarly
named..."  I wanted to cut down that pretentious lstddrv.c a little,
too.

Please try the attached patch (only SIGARLM is used, although I guess
SIGIO would theoretically be more responsive).

P.S. Just curious, but what was the reason you guys are using signals
instead of threads?  To quote Vincent: Not pushing, just asking :-)

-- 
王浩禎
Index: makefile.lst
===================================================================
RCS file: /cvsroot/alleg/allegro/makefile.lst,v
retrieving revision 1.58.2.3
diff -u -r1.58.2.3 makefile.lst
--- makefile.lst	20 May 2003 17:24:49 -0000	1.58.2.3
+++ makefile.lst	3 Jul 2003 06:21:29 -0000
@@ -232,7 +232,6 @@
 
 ALLEGRO_SRC_LINUX_FILES = \
 	src/linux/fbcon.c \
-	src/linux/lasyncio.c \
 	src/linux/lconsole.c \
 	src/linux/lgfxdrv.c \
 	src/linux/ljoy.c \
Index: include/linalleg.h
===================================================================
RCS file: /cvsroot/alleg/allegro/include/linalleg.h,v
retrieving revision 1.2
diff -u -r1.2 linalleg.h
--- include/linalleg.h	24 Nov 2001 11:52:24 -0000	1.2
+++ include/linalleg.h	3 Jul 2003 06:22:36 -0000
@@ -10,10 +10,8 @@
  *
  *      Linux header file for the Allegro library.
  *
- *      This doesn't need to be included; it prototypes functions you
- *      can use to control the library more closely.
- *
- *      By George Foot.
+ *      This file no longer contains anything.  At the moment,
+ *      it exists only for backwards compatibility.
  *
  *      See readme.txt for copyright information.
  */
@@ -22,34 +20,9 @@
 #ifndef LIN_ALLEGRO_H
 #define LIN_ALLEGRO_H
 
-#ifdef __cplusplus
-   extern "C" {
-#endif
-
-#ifndef ALLEGRO_H
-#error Please include allegro.h before linalleg.h!
-#endif
-
-
-/******************************************/
-/************ Asynchronous I/O ************/
-/******************************************/
-
-#define ASYNC_OFF            0x00
-#define ASYNC_DEFAULT        0x01
-#define ASYNC_BSD            0x02
-#define ASYNC_THREADS        0x03
-
-typedef RETSIGTYPE (*SIGIO_HOOK)(int);
-
-SIGIO_HOOK al_linux_install_sigio_hook (SIGIO_HOOK hook);
-int al_linux_set_async_mode (unsigned type);
-int al_linux_is_async_mode (void);
-
-
-#ifdef __cplusplus
-   }
-#endif
+/* If a header file disappeared from a system include path, but no
+ * one's programs ever included it, does it go "pop"?
+ */
 
 #endif          /* ifndef LIN_ALLEGRO_H */
 
Index: include/allegro/platform/aintlnx.h
===================================================================
RCS file: /cvsroot/alleg/allegro/include/allegro/platform/aintlnx.h,v
retrieving revision 1.3
diff -u -r1.3 aintlnx.h
--- include/allegro/platform/aintlnx.h	13 Nov 2001 22:52:13 -0000	1.3
+++ include/allegro/platform/aintlnx.h	3 Jul 2003 06:22:36 -0000
@@ -59,51 +59,37 @@
 /************ Standard drivers ************/ /* (src/linux/lstddrv.c) */
 /******************************************/
 
-#define PRIVATE_SIZE   1
+/* This "standard drivers" business is mostly a historical artifact.
+ * It was highly over-engineered, now simplified.  It has been mostly
+ * superseded by the newer, shinier, better bg_man.  But hey, at least
+ * it didn't suffer the fate of its cousin lasyncio.c, now dead,
+ * buried, and without a tombstone to show for it. --pw
+ */
 
 typedef struct STD_DRIVER {
-   unsigned    type; /* One of the above STD_ constants */
+   unsigned    type; /* One of the below STD_ constants */
 
    int (*update) (void);
    void (*resume) (void);
    void (*suspend) (void);
 
    int         fd;   /* Descriptor of the opened device */
-
-#ifndef __cplusplus
-   unsigned    private[PRIVATE_SIZE];
-#else
-   unsigned    priv[PRIVATE_SIZE];
-#endif
 } STD_DRIVER;
 
-#define STD_RTC              0
-#define STD_MOUSE            1
-#define STD_KBD              2
+#define STD_MOUSE            0
+#define STD_KBD              1
 
-#define N_STD_DRIVERS        3
+#define N_STD_DRIVERS        2
 
 /* List of standard drivers */
 extern STD_DRIVER *__al_linux_std_drivers[];
 
-/* Indices of the fields in the STD_DRIVER.private array */
-#define PRIV_ENABLED       0
-
 /* Exported functions */
 int  __al_linux_add_standard_driver (STD_DRIVER *spec);
 int  __al_linux_remove_standard_driver (STD_DRIVER *spec);
-int  __al_linux_update_standard_driver (int type);
-void __al_linux_update_standard_drivers (void);
-void __al_linux_async_set_drivers (int which, int on_off);
-void __al_linux_disable_standard_driver (int type);
-void __al_linux_enable_standard_driver (int type);
-
-
-/******************************************/
-/************ Asynchronous I/O ************/ /* (src/linux/lasyncio.c) */
-/******************************************/
-
-extern unsigned __al_linux_async_io_mode;
+void __al_linux_update_standard_drivers (int threaded);
+void __al_linux_suspend_standard_drivers (void);
+void __al_linux_resume_standard_drivers (void);
 
 
 /******************************************/
Index: src/linux/lkeybd.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/linux/lkeybd.c,v
retrieving revision 1.5.2.2
diff -u -r1.5.2.2 lkeybd.c
--- src/linux/lkeybd.c	7 Feb 2003 12:41:09 -0000	1.5.2.2
+++ src/linux/lkeybd.c	3 Jul 2003 06:23:22 -0000
@@ -62,8 +62,7 @@
    update_keyboard,
    resume_keyboard,
    suspend_keyboard,
-   -1,  /* fd -- filled in later */
-   { 0 }
+   -1   /* fd -- filled in later */
 };
 
 
Index: src/linux/lmouse.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/linux/lmouse.c,v
retrieving revision 1.3.2.1
diff -u -r1.3.2.1 lmouse.c
--- src/linux/lmouse.c	7 Feb 2003 12:41:09 -0000	1.3.2.1
+++ src/linux/lmouse.c	3 Jul 2003 06:24:19 -0000
@@ -163,8 +163,7 @@
    update_mouse,
    resume_mouse,
    suspend_mouse,
-   -1,  /* fd -- filled in later */
-   { 0 }
+   -1   /* fd -- filled in later */
 };
 
 
Index: src/linux/lstddrv.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/linux/lstddrv.c,v
retrieving revision 1.4
diff -u -r1.4 lstddrv.c
--- src/linux/lstddrv.c	6 Nov 2001 17:16:40 -0000	1.4
+++ src/linux/lstddrv.c	3 Jul 2003 06:24:19 -0000
@@ -30,41 +30,7 @@
 /* List of standard drivers */
 STD_DRIVER *__al_linux_std_drivers[N_STD_DRIVERS];
 
-
-static void __async_disable_driver (STD_DRIVER *drv, int mode)
-{
-   switch (mode) {
-      case ASYNC_BSD:
-      {
-         int   flags = fcntl(drv->fd, F_GETFL, 0);
-         fcntl(drv->fd, F_SETFL, flags & ~FASYNC);
-         break;
-      }
-      case ASYNC_OFF:
-         break;
-   }
-
-   drv->private[PRIV_ENABLED] = 0;
-   drv->suspend();
-}
-
-static void __async_enable_driver (STD_DRIVER *drv, int mode)
-{
-   drv->resume();
-   drv->private[PRIV_ENABLED] = 1;
-
-   switch (mode) {
-      case ASYNC_BSD:
-      {
-         int flags = fcntl(drv->fd, F_GETFL, 0);
-         fcntl(drv->fd, F_SETOWN, getpid());
-         fcntl(drv->fd, F_SETFL, flags | FASYNC);
-         break;
-      }
-      case ASYNC_OFF:
-         break;
-   }
-}
+static int std_drivers_suspended = FALSE;
 
 
 /* __al_linux_add_standard_driver:
@@ -78,10 +44,9 @@
    if (!spec->update) return 3;
    if (spec->fd < 0) return 4;
 
-   spec->private[PRIV_ENABLED] = 0;
    __al_linux_std_drivers[spec->type] = spec;
 
-   __async_enable_driver (spec, __al_linux_async_io_mode);
+   spec->resume();
 
    return 0;
 }
@@ -93,12 +58,11 @@
 int __al_linux_remove_standard_driver (STD_DRIVER *spec)
 {
    if (!spec) return 1;
-   /*if (!__al_linux_async_io_mode) return 2;*/
    if (spec->type >= N_STD_DRIVERS) return 3;
    if (!__al_linux_std_drivers[spec->type]) return 4; 
    if (__al_linux_std_drivers[spec->type] != spec) return 5;
 
-   __async_disable_driver (spec, __al_linux_async_io_mode);
+   spec->suspend();
    
    __al_linux_std_drivers[spec->type] = NULL;
 
@@ -106,64 +70,35 @@
 }
 
 
-/* __al_linux_update_standard_driver:
- *  Calls the driver's update method.
- */
-int __al_linux_update_standard_driver (int type)
-{
-   if (type >= N_STD_DRIVERS) return -1;
-   if (!__al_linux_std_drivers[type]) return -1;
-
-   if (__al_linux_std_drivers[type]->private[PRIV_ENABLED])
-      return __al_linux_std_drivers[type]->update();
-
-   return 0;
-}
-
-
 /* __al_linux_update_standard_drivers:
  *  Updates all drivers.
  */
-void __al_linux_update_standard_drivers (void)
+void __al_linux_update_standard_drivers (int threaded)
 {
    int i;
-   for (i = 0; i < N_STD_DRIVERS; i++)
-      if (__al_linux_std_drivers[i] && __al_linux_std_drivers[i]->private[PRIV_ENABLED])
-         __al_linux_std_drivers[i]->update();
+   if (!std_drivers_suspended) {
+      for (i = 0; i < N_STD_DRIVERS; i++)
+	 if (__al_linux_std_drivers[i])
+	    __al_linux_std_drivers[i]->update();
+   }
 }
 
 
-/* __al_linux_async_set_drivers:
- *  Enables/disables drivers, with async mode `mode' at the time --
- *  used when switching between async modes.
+/* __al_linux_suspend_standard_drivers:
+ *  Temporary disable standard drivers during a VT switch.
  */
-void __al_linux_async_set_drivers (int mode, int on_off)
-{
-   int i;
-   for (i = 0; i < N_STD_DRIVERS; i++)
-      if (__al_linux_std_drivers[i]) {
-         if (on_off)
-            __async_enable_driver (__al_linux_std_drivers[i], mode);
-         else
-            __async_disable_driver (__al_linux_std_drivers[i], mode);
-      }
-}
-
-
-
-void __al_linux_disable_standard_driver (int type)
+void __al_linux_suspend_standard_drivers (void)
 {
-   if (type >= N_STD_DRIVERS) return;
-   if (!__al_linux_std_drivers[type]) return;
-
-   __async_disable_driver(__al_linux_std_drivers[type], __al_linux_async_io_mode);
+   ASSERT(!std_drivers_suspended);
+   std_drivers_suspended = TRUE;
 }
 
-void __al_linux_enable_standard_driver (int type)
+/* __al_linux_resume_standard_drivers:
+ *  Re-enable standard drivers after a VT switch.
+ */
+void __al_linux_resume_standard_drivers (void)
 {
-   if (type >= N_STD_DRIVERS) return;
-   if (!__al_linux_std_drivers[type]) return;
-
-   __async_enable_driver(__al_linux_std_drivers[type], __al_linux_async_io_mode);
+   ASSERT(std_drivers_suspended);
+   std_drivers_suspended = FALSE;
 }
 
Index: src/linux/lsystem.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/linux/lsystem.c,v
retrieving revision 1.17.2.1
diff -u -r1.17.2.1 lsystem.c
--- src/linux/lsystem.c	7 Feb 2003 12:41:09 -0000	1.17.2.1
+++ src/linux/lsystem.c	3 Jul 2003 06:24:19 -0000
@@ -117,42 +117,27 @@
 }
 
 
-/* linux_bg_handler:
- *  Used for handling asynchronous event processing.
- */
-static void linux_bg_handler (int threaded)
-{
-	__al_linux_update_standard_drivers();
-}
-
-
-/* __al_linux_async_init:
+/* __al_linux_bgman_init:
  *  Starts asynchronous processing.
  */
-static int __al_linux_async_init (void)
+static int __al_linux_bgman_init (void)
 {
 #ifdef HAVE_LIBPTHREAD
 	_unix_bg_man = &_bg_man_pthreads;
 #else
 	_unix_bg_man = &_bg_man_sigalrm;
 #endif
-	if (_unix_bg_man->init() || _unix_bg_man->register_func (linux_bg_handler))
+	if (_unix_bg_man->init() || _unix_bg_man->register_func (__al_linux_update_standard_drivers))
 		return -1;
-#ifndef HAVE_LIBPTHREAD
-	al_linux_set_async_mode (ASYNC_DEFAULT);
-#endif
 	return 0;
 }
 
 
-/* __al_linux_async_exit:
+/* __al_linux_bgman_exit:
  *  Stops asynchronous processing.
  */
-static void __al_linux_async_exit (void)
+static void __al_linux_bgman_exit (void)
 {
-#ifndef HAVE_LIBPTHREAD
-	al_linux_set_async_mode (ASYNC_OFF);
-#endif
 	_unix_bg_man->exit();
 }
 
@@ -204,7 +189,7 @@
 #endif
 
 	/* Initialise async event processing */
-    	if (__al_linux_async_init()) {
+    	if (__al_linux_bgman_init()) {
 		/* shutdown everything.  */
 		sys_linux_exit();
 		return -1;
@@ -228,7 +213,7 @@
 	__al_linux_done_vtswitch();
 
 	/* shut down asynchronous event processing */
-	__al_linux_async_exit();
+	__al_linux_bgman_exit();
 
 	/* remove emergency exit signal handlers */
 	signal(SIGABRT, old_sig_abrt);
Index: src/linux/vtswitch.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/linux/vtswitch.c,v
retrieving revision 1.8.2.2
diff -u -r1.8.2.2 vtswitch.c
--- src/linux/vtswitch.c	7 Feb 2003 13:35:56 -0000	1.8.2.2
+++ src/linux/vtswitch.c	3 Jul 2003 06:24:19 -0000
@@ -133,8 +133,7 @@
 		if (timer_driver) timer_driver->exit();
 
 	/* Disable input devices while we're away */
-	__al_linux_disable_standard_driver(STD_MOUSE);
-	__al_linux_disable_standard_driver(STD_KBD);
+	__al_linux_suspend_standard_drivers();
 
 	_save_switch_state(switch_mode);
 
@@ -173,8 +172,7 @@
 	ioctl(__al_linux_console_fd, VT_RELDISP, VT_ACKACQ);
 	console_active = 1;
 
-	__al_linux_enable_standard_driver(STD_KBD);
-	__al_linux_enable_standard_driver(STD_MOUSE);
+	__al_linux_resume_standard_drivers();
 
 	_unix_bg_man->enable_interrupts();
 


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