Re: [AD] proposal: al_sleep() |
[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
On Mon, 2003-12-29 at 10:07, Eric Botcazou wrote:
> > but since Allegro already has yield_timeslice () - which is rather
> > useless in my opinion - shouldn't we provide an al_sleep(), with
> > al_sleep(0) deprecating yield_timeslice()?
>
> Yes, this makes sense I think.
>
I just started implementing al_sleep, and noticed that yield_timeslice
behaves quite differently under windows and unix compared to other
platforms. BeOS and OSX sleep 30000 micro-seconds, QNX sleeps 10000
micro-seconds. Windows sleeps 0 milliseconds (not at all), same as unix
which calls sched_yield.
Therefore, I'd like to first apply the attached patch, which improves
the bahavior of yield_timeslice under Windows and Unix (and
yield_timeslice can't be deprecated by al_sleep anyway - since
apparently the amount of sleeping time needs to be significantly higher
than 0 under the 3 operating systems I mentioned at first above.)
I have no idea what the advantage of sched_yield is - but at least for
me, it causes 100% CPU usage - so the patch removes support for it.
(Patch only tested under linux.)
PS: I seem to have trouble sending to SF lists - sorry if this arrives multiple times.
--
Elias Pschernig <elias@xxxxxxxxxx>
Index: configure.in
===================================================================
RCS file: /cvsroot/alleg/allegro/configure.in,v
retrieving revision 1.70
diff -r1.70 configure.in
300,305d299
< dnl Test where is 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
<
Index: aclocal.m4
===================================================================
RCS file: /cvsroot/alleg/allegro/aclocal.m4,v
retrieving revision 1.54
diff -r1.54 aclocal.m4
549,562d548
< dnl Test where is 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
Index: src/unix/usystem.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/unix/usystem.c,v
retrieving revision 1.24
diff -r1.24 usystem.c
28,36c28
< #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
---
> #include <sys/time.h>
216,227c208,211
< #if defined(ALLEGRO_USE_SCHED_YIELD) && defined(_POSIX_PRIORITY_SCHEDULING)
<
< sched_yield();
<
< #else
<
< struct timeval timeout;
< timeout.tv_sec = 0;
< timeout.tv_usec = 1;
< select(0, NULL, NULL, NULL, &timeout);
<
< #endif
---
> struct timeval timeout;
> timeout.tv_sec = 0;
> timeout.tv_usec = 1;
> select(0, NULL, NULL, NULL, &timeout);
Index: src/win/wsystem.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/win/wsystem.c,v
retrieving revision 1.51
diff -r1.51 wsystem.c
430c430
< Sleep(0);
---
> Sleep(1);