Re: [AD] rest and yield_timeslice

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


On Mon, 2004-07-19 at 16:24 +0200, Elias Pschernig wrote:
> The attached patch:
This one.

-- 
Elias Pschernig
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	19 Jul 2004 14:25:56 -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 long time, void (*callback)(void))
 {
+   if (!time) {
+      system_driver->yield_timeslice();
+      return;
+   }
    if (timer_driver) {
       if (timer_driver->rest) {
 	 timer_driver->rest(time, callback);
@@ -182,7 +186,7 @@ void rest_callback(long time, void (*cal
 /* rest:
  *  Waits for time milliseconds.
  */
-void rest(long time)
+void rest(unsigned long time)
 {
    rest_callback(time, NULL);
 }
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	19 Jul 2004 14:25:59 -0000
@@ -46,7 +46,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 long time, AL_METHOD(void, callback, (void))));
 } TIMER_DRIVER;
 
 
@@ -71,8 +71,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 long time));
+AL_FUNC(void, rest_callback, (unsigned long time, AL_METHOD(void, callback, (void))));
 
 #ifdef __cplusplus
    }
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	19 Jul 2004 14:25:59 -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	19 Jul 2004 14:25:59 -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: 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	19 Jul 2004 14:25:59 -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/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	19 Jul 2004 14:25:59 -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	19 Jul 2004 14:25:59 -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/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	19 Jul 2004 14:25:59 -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: 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	19 Jul 2004 14:26:00 -0000
@@ -55,6 +55,10 @@ extern "C" {
    AL_FUNC(void, _unix_yield_timeslice, (void));
 
 
+   /* Unix rest function */
+   AL_FUNC(void, _unix_rest, (unsigned long, 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/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	19 Jul 2004 14:26:00 -0000
@@ -427,7 +427,7 @@ static void sys_directx_get_gfx_safe_mod
  */
 static void sys_directx_yield_timeslice(void)
 {
-   Sleep(1);
+   Sleep(0);
 }
 
 


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