Re: [AD] WIP 4.1.15 and CVS freeze

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


On Fri, 2004-07-23 at 21:16 +0200, Elias Pschernig wrote:

> Well, there are no backwards compatibility problems with it - so that
> would be unnecessary. Changing the parameter to unsigned just fixes the
> problem of the undefined behavior with negative numbers. If others think
> it shouldn't be done, I'll just put an ASSERT.
> 

The attached patch is the same as the last, but I added in the
YIELD_TIME constant, adjusted the GUI and examples to use it, and
deprecated yield_timeslice.

Once it is applied, system_driver->yield_timeslice on BeOS/QNX/MacOSX
should be adjusted to behave like on other systems (no waiting).

So, if somebody except Chris thinks rest() should have "long" instead of
"unsigned int" as parameter.. complain. Since negative values were never
allowed, this should have no backwards compatibility problems, and
solves the problem of the undefined negative values, which is what all
other waiting functions i could find in other libs do as well.

-- 
Elias Pschernig
Index: aclocal.m4
===================================================================
RCS file: /cvsroot/alleg/allegro/aclocal.m4,v
retrieving revision 1.63
diff -u -p -r1.63 aclocal.m4
--- aclocal.m4	11 Jul 2004 10:38:45 -0000	1.63
+++ aclocal.m4	25 Jul 2004 19:27:30 -0000
@@ -603,6 +603,20 @@ LIBS="-lpthread $LIBS"
 allegro_cv_support_pthreads=yes))])
 
 dnl
+dnl Test for sched_yield (SunOS).
+dnl
+dnl Variables:
+dnl  allegro_cv_support_sched_yield=(yes|)
+dnl
+dnl LIBS can be modified.
+dnl
+AC_DEFUN(ALLEGRO_ACTEST_SCHED_YIELD,
+[AC_CHECK_LIB(c, sched_yield,
+allegro_cv_support_sched_yield=yes,
+AC_SEARCH_LIBS(sched_yield, posix4 rt,
+allegro_cv_support_sched_yield=yes))])
+
+dnl
 dnl Test for constructor attribute support.
 dnl
 dnl Variables:
Index: configure.in
===================================================================
RCS file: /cvsroot/alleg/allegro/configure.in,v
retrieving revision 1.79
diff -u -p -r1.79 configure.in
--- configure.in	15 May 2004 09:05:10 -0000	1.79
+++ configure.in	25 Jul 2004 19:27:31 -0000
@@ -205,6 +205,12 @@ if test "$Xallegro_cv_have_map_failed" =
 	    [Define to (void *)-1, if MAP_FAILED is not defined.])
 fi
 
+dnl Test for sched_yield (SunOS).
+ALLEGRO_ACTEST_SCHED_YIELD
+if test "X$allegro_cv_support_sched_yield" = "Xyes"; then
+   AC_DEFINE(ALLEGRO_USE_SCHED_YIELD,1,[Define if sched_yield is provided by some library.])
+fi
+
 dnl Test for constructor attribute support.
 ALLEGRO_ACTEST_CONSTRUCTOR
 if test "X$allegro_support_constructor" = "Xyes"; then
Index: include/allegro/alcompat.h
===================================================================
RCS file: /cvsroot/alleg/allegro/include/allegro/alcompat.h,v
retrieving revision 1.15
diff -u -p -r1.15 alcompat.h
--- include/allegro/alcompat.h	29 Nov 2003 07:24:18 -0000	1.15
+++ include/allegro/alcompat.h	25 Jul 2004 19:29:01 -0000
@@ -219,6 +219,16 @@ AL_INLINE_DEPRECATED(void, set_window_cl
 AL_FUNC_DEPRECATED(void, set_clip, (BITMAP *bitmap, int x1, int y1, int x2, int y2));
 
 
+/* unnecessary, can use rest(0) */
+AL_INLINE_DEPRECATED(void, yield_timeslice, (void),
+{
+   ASSERT(system_driver);
+
+   if (system_driver->yield_timeslice)
+      system_driver->yield_timeslice();
+})
+
+
 #ifdef __cplusplus
    }
 #endif
Index: include/allegro/timer.h
===================================================================
RCS file: /cvsroot/alleg/allegro/include/allegro/timer.h,v
retrieving revision 1.2
diff -u -p -r1.2 timer.h
--- include/allegro/timer.h	31 Oct 2002 12:56:24 -0000	1.2
+++ include/allegro/timer.h	25 Jul 2004 19:29:04 -0000
@@ -31,6 +31,14 @@
 #define BPS_TO_TIMER(x)       (TIMERS_PER_SECOND / (long)(x))
 #define BPM_TO_TIMER(x)       ((60 * TIMERS_PER_SECOND) / (long)(x))
 
+/* Use a longer yield period on some platforms, to give up CPU. */
+#if defined (ALLEGRO_QNX) || defined (ALLEGRO_BEOS)
+#define YIELD_TIME 10
+#elif defined (ALLEGRO_MACOSX)
+#define YIELD_TIME 30
+#else
+#define YIELD_TIME 1
+#endif
 
 typedef struct TIMER_DRIVER
 {
@@ -46,7 +54,7 @@ typedef struct TIMER_DRIVER
    AL_METHOD(void, remove_param_int, (AL_METHOD(void, proc, (void *param)), void *param));
    AL_METHOD(int,  can_simulate_retrace, (void));
    AL_METHOD(void, simulate_retrace, (int enable));
-   AL_METHOD(void, rest, (long time, AL_METHOD(void, callback, (void))));
+   AL_METHOD(void, rest, (unsigned int time, AL_METHOD(void, callback, (void))));
 } TIMER_DRIVER;
 
 
@@ -71,8 +79,8 @@ AL_FUNC(int,  timer_can_simulate_retrace
 AL_FUNC(void, timer_simulate_retrace, (int enable));
 AL_FUNC(int,  timer_is_using_retrace, (void));
 
-AL_FUNC(void, rest, (long time));
-AL_FUNC(void, rest_callback, (long time, AL_METHOD(void, callback, (void))));
+AL_FUNC(void, rest, (unsigned int time));
+AL_FUNC(void, rest_callback, (unsigned int time, AL_METHOD(void, callback, (void))));
 
 #ifdef __cplusplus
    }
Index: include/allegro/inline/system.inl
===================================================================
RCS file: /cvsroot/alleg/allegro/include/allegro/inline/system.inl,v
retrieving revision 1.4
diff -u -p -r1.4 system.inl
--- include/allegro/inline/system.inl	17 Dec 2002 09:28:58 -0000	1.4
+++ include/allegro/inline/system.inl	25 Jul 2004 19:29:05 -0000
@@ -57,14 +57,6 @@ AL_INLINE(int, get_desktop_resolution, (
 })
 
 
-AL_INLINE(void, yield_timeslice, (void),
-{
-   ASSERT(system_driver);
-
-   if (system_driver->yield_timeslice)
-      system_driver->yield_timeslice();
-})
-
 
 #ifdef __cplusplus
    }
Index: include/allegro/platform/aintunix.h
===================================================================
RCS file: /cvsroot/alleg/allegro/include/allegro/platform/aintunix.h,v
retrieving revision 1.7
diff -u -p -r1.7 aintunix.h
--- include/allegro/platform/aintunix.h	15 Jul 2004 17:15:45 -0000	1.7
+++ include/allegro/platform/aintunix.h	25 Jul 2004 19:29:08 -0000
@@ -55,6 +55,10 @@ extern "C" {
    AL_FUNC(void, _unix_yield_timeslice, (void));
 
 
+   /* Unix rest function */
+   AL_FUNC(void, _unix_rest, (unsigned int, AL_METHOD(void, callback, (void))));
+
+
    /* Module support */
    AL_FUNC(void, _unix_load_modules, (int system_driver));
    AL_FUNC(void, _unix_unload_modules, (void));
Index: src/gui.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/gui.c,v
retrieving revision 1.69
diff -u -p -r1.69 gui.c
--- src/gui.c	14 Jul 2004 02:04:33 -0000	1.69
+++ src/gui.c	25 Jul 2004 19:29:53 -0000
@@ -782,7 +782,7 @@ int do_dialog(DIALOG *dialog, int focus_
        * engine is shut down so no user code can be running.
        */
       if (active_menu_player)
-         yield_timeslice();
+         rest(YIELD_TIME);
    }
 
    if (_gfx_mode_set_count == screen_count)
@@ -1695,7 +1695,7 @@ int do_menu(MENU *menu, int x, int y)
    player = init_menu(menu, x ,y);
 
    while (update_menu(player))
-      yield_timeslice();
+      rest(YIELD_TIME);
 
    ret = shutdown_menu(player);
 
Index: src/guiproc.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/guiproc.c,v
retrieving revision 1.25
diff -u -p -r1.25 guiproc.c
--- src/guiproc.c	29 Nov 2003 07:24:19 -0000	1.25
+++ src/guiproc.c	25 Jul 2004 19:29:56 -0000
@@ -137,7 +137,7 @@ static void dotted_rect(int x1, int y1, 
 int d_yield_proc(int msg, DIALOG *d, int c)
 {
    if (msg == MSG_IDLE)
-      yield_timeslice();
+      rest(YIELD_TIME);
 
    return D_O_K;
 }
Index: src/keyboard.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/keyboard.c,v
retrieving revision 1.8
diff -u -p -r1.8 keyboard.c
--- src/keyboard.c	15 May 2004 13:05:32 -0000	1.8
+++ src/keyboard.c	25 Jul 2004 19:29:56 -0000
@@ -231,7 +231,7 @@ int ureadkey(int *scancode)
       if (keyboard_polled)
 	 poll_keyboard();
 
-      yield_timeslice();
+      rest(YIELD_TIME);
    }
 
    c = key_buffer.key[key_buffer.start];
Index: src/timer.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/timer.c,v
retrieving revision 1.14
diff -u -p -r1.14 timer.c
--- src/timer.c	21 Sep 2003 15:50:47 -0000	1.14
+++ src/timer.c	25 Jul 2004 19:30:11 -0000
@@ -147,8 +147,12 @@ END_OF_STATIC_FUNCTION(rest_int);
 /* rest_callback:
  *  Waits for time milliseconds.
  */
-void rest_callback(long time, void (*callback)(void))
+void rest_callback(unsigned int time, void (*callback)(void))
 {
+   if (!time) {
+      system_driver->yield_timeslice();
+      return;
+   }
    if (timer_driver) {
       if (timer_driver->rest) {
 	 timer_driver->rest(time, callback);
@@ -163,7 +167,7 @@ void rest_callback(long time, void (*cal
 	    if (callback)
 	       callback();
 	    else
-	       yield_timeslice();
+	       system_driver->yield_timeslice();
 
 	 } while (rest_count > 0);
 
@@ -173,6 +177,7 @@ void rest_callback(long time, void (*cal
    else {
       time = clock() + MIN(time * CLOCKS_PER_SEC / 1000, 2);
       do {
+         system_driver->yield_timeslice();
       } while (clock() < (clock_t)time);
    }
 }
@@ -182,7 +187,7 @@ void rest_callback(long time, void (*cal
 /* rest:
  *  Waits for time milliseconds.
  */
-void rest(long time)
+void rest(unsigned int time)
 {
    rest_callback(time, NULL);
 }
Index: src/unix/uptimer.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/unix/uptimer.c,v
retrieving revision 1.8
diff -u -p -r1.8 uptimer.c
--- src/unix/uptimer.c	4 Oct 2003 20:03:58 -0000	1.8
+++ src/unix/uptimer.c	25 Jul 2004 19:31:19 -0000
@@ -18,6 +18,7 @@
 
 #include "allegro.h"
 #include "allegro/internal/aintern.h"
+#include "allegro/platform/aintunix.h"
 
 
 #ifdef HAVE_LIBPTHREAD
@@ -58,7 +59,7 @@ TIMER_DRIVER timerdrv_unix_pthreads =
    NULL, NULL,		/* install_int, remove_int */
    NULL, NULL,		/* install_param_int, remove_param_int */
    NULL, NULL,		/* can_simulate_retrace, simulate_retrace */
-   NULL			/* rest */
+   _unix_rest		/* rest */
 };
 
 
Index: src/unix/ustimer.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/unix/ustimer.c,v
retrieving revision 1.4
diff -u -p -r1.4 ustimer.c
--- src/unix/ustimer.c	12 Jul 2003 03:28:01 -0000	1.4
+++ src/unix/ustimer.c	25 Jul 2004 19:31:20 -0000
@@ -41,7 +41,7 @@ TIMER_DRIVER timerdrv_unix_sigalrm =
    NULL, NULL,		/* install_int, remove_int */
    NULL, NULL,		/* install_param_int, remove_param_int */
    NULL, NULL,		/* can_simulate_retrace, simulate_retrace */
-   NULL			/* rest */
+   _unix_rest		/* rest */
 };
 
 
Index: src/unix/usystem.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/unix/usystem.c,v
retrieving revision 1.26
diff -u -p -r1.26 usystem.c
--- src/unix/usystem.c	2 Jul 2004 16:25:42 -0000	1.26
+++ src/unix/usystem.c	25 Jul 2004 19:31:20 -0000
@@ -25,7 +25,15 @@
 #include "allegro.h"
 #include "allegro/platform/aintunix.h"
 
-#include <sys/time.h>
+#if defined(ALLEGRO_USE_SCHED_YIELD) && defined(_POSIX_PRIORITY_SCHEDULING)
+   /* ALLEGRO_USE_SCHED_YIELD is set by configure */
+   /* Manpages say systems providing sched_yield() define
+    * _POSIX_PRIORITY_SCHEDULING in unistd.h
+    */
+   #include <sched.h>
+#else
+   #include <sys/time.h>
+#endif
 
 #ifdef HAVE_SYS_UTSNAME_H
    #include <sys/utsname.h>
@@ -205,10 +213,18 @@ void _read_os_type()
  */
 void _unix_yield_timeslice(void)
 {
-  struct timeval timeout;
-  timeout.tv_sec = 0;
-  timeout.tv_usec = 1;
-  select(0, NULL, NULL, NULL, &timeout);
+   #if defined(ALLEGRO_USE_SCHED_YIELD) && defined(_POSIX_PRIORITY_SCHEDULING)
+
+      sched_yield();
+
+   #else
+
+      struct timeval timeout;
+      timeout.tv_sec = 0;
+      timeout.tv_usec = 0;
+      select(0, NULL, NULL, NULL, &timeout);
+
+   #endif
 }
 
 
Index: src/unix/utimer.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/unix/utimer.c,v
retrieving revision 1.3
diff -u -p -r1.3 utimer.c
--- src/unix/utimer.c	9 Aug 2001 12:01:15 -0000	1.3
+++ src/unix/utimer.c	25 Jul 2004 19:31:20 -0000
@@ -17,7 +17,7 @@
 
 
 #include "allegro.h"
-
+#include <sys/time.h>
 
 
 /* System drivers provide their own lists, so this is just to keep the 
@@ -26,3 +26,20 @@ _DRIVER_INFO _timer_driver_list[] = {
    { 0, 0, 0 }
 };
 
+
+
+void _unix_rest(unsigned long ms, void (*callback) (void))
+{
+   if (callback) {
+      clock_t start = clock();
+      clock_t end = start + ms * CLOCKS_PER_SEC / 1000;
+      while (clock() < end)
+         (*callback)();
+   }
+   else {
+      struct timeval timeout;
+      timeout.tv_sec = 0;
+      timeout.tv_usec = ms * 1000;
+      select(0, NULL, NULL, NULL, &timeout);
+   }
+}
Index: src/win/wsystem.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/win/wsystem.c,v
retrieving revision 1.52
diff -u -p -r1.52 wsystem.c
--- src/win/wsystem.c	19 Jan 2004 17:30:55 -0000	1.52
+++ src/win/wsystem.c	25 Jul 2004 19:31:32 -0000
@@ -427,7 +427,7 @@ static void sys_directx_get_gfx_safe_mod
  */
 static void sys_directx_yield_timeslice(void)
 {
-   Sleep(1);
+   Sleep(0);
 }
 
 
Index: src/win/wtimer.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/win/wtimer.c,v
retrieving revision 1.15
diff -u -p -r1.15 wtimer.c
--- src/win/wtimer.c	26 Aug 2002 07:43:50 -0000	1.15
+++ src/win/wtimer.c	25 Jul 2004 19:31:32 -0000
@@ -47,7 +47,7 @@ _DRIVER_INFO _timer_driver_list[] =
 static int tim_win32_high_perf_init(void);
 static int tim_win32_low_perf_init(void);
 static void tim_win32_exit(void);
-static void tim_win32_rest(long time, AL_METHOD(void, callback, (void)));
+static void tim_win32_rest(unsigned int time, AL_METHOD(void, callback, (void)));
 
 
 TIMER_DRIVER timer_win32_high_perf =
@@ -252,10 +252,10 @@ static void tim_win32_exit(void)
 /* tim_win32_rest:
  *  Rests the specified amount of milliseconds.
  */
-static void tim_win32_rest(long time, AL_METHOD(void, callback, (void)))
+static void tim_win32_rest(unsigned int time, AL_METHOD(void, callback, (void)))
 {
-   unsigned long start;
-   unsigned long ms = time;
+   unsigned int start;
+   unsigned int ms = time;
 
    if (callback) {
       start = timeGetTime();
Index: src/beos/btimeapi.cpp
===================================================================
RCS file: /cvsroot/alleg/allegro/src/beos/btimeapi.cpp,v
retrieving revision 1.8
diff -u -p -r1.8 btimeapi.cpp
--- src/beos/btimeapi.cpp	6 Nov 2001 17:16:39 -0000	1.8
+++ src/beos/btimeapi.cpp	25 Jul 2004 19:43:15 -0000
@@ -123,7 +123,7 @@ extern "C" void be_time_exit(void)
 
 /* be_time_rest:
  */
-extern "C" void be_time_rest(long time, AL_METHOD(void, callback, (void)))
+extern "C" void be_time_rest(unsigned int time, AL_METHOD(void, callback, (void)))
 {
    time *= 1000;
 
Index: include/allegro/platform/aintbeos.h
===================================================================
RCS file: /cvsroot/alleg/allegro/include/allegro/platform/aintbeos.h,v
retrieving revision 1.9
diff -u -p -r1.9 aintbeos.h
--- include/allegro/platform/aintbeos.h	8 Feb 2003 21:35:00 -0000	1.9
+++ include/allegro/platform/aintbeos.h	25 Jul 2004 19:44:41 -0000
@@ -111,7 +111,7 @@ int  be_time_init(void);
 void be_time_exit(void);
 //int  be_time_can_simulate_retrace(void);
 //void be_time_simulate_retrace(int enable);
-void be_time_rest(long time, AL_METHOD(void, callback, (void)));
+void be_time_rest(unsigned int time, AL_METHOD(void, callback, (void)));
 void be_time_suspend(void);
 void be_time_resume(void);
 


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