From 8752414fa87753c0438af7bd137438f20c7af9b2 Mon Sep 17 00:00:00 2001 From: Cameron Cawley Date: Sun, 25 Jul 2021 16:06:25 +0100 Subject: [PATCH] Replace direct use of usleep() --- Makefile.os2 | 4 +-- Makefile.w32 | 4 +-- configure.ac | 4 +-- src/Makefile.am | 7 +++-- src/common.h | 2 ++ src/delay.c | 61 +++++++++++++++++++++++++++++++++++++++++++ src/main.c | 2 +- src/sound_coreaudio.c | 3 +-- src/watcom/unistd.h | 2 -- src/watcom/usleep.c | 14 ---------- src/win32/unistd.h | 2 -- src/win32/usleep.c | 48 ---------------------------------- vc/xmp.vcproj | 8 +++--- 13 files changed, 78 insertions(+), 83 deletions(-) create mode 100644 src/delay.c delete mode 100644 src/watcom/usleep.c delete mode 100644 src/win32/usleep.c diff --git a/Makefile.os2 b/Makefile.os2 index f7ed24c..e3bf7d8 100644 --- a/Makefile.os2 +++ b/Makefile.os2 @@ -32,14 +32,14 @@ CFLAGS+= -5s AOUT=xmp.exe COMPILE=$(CC) $(CFLAGS) $(CPPFLAGS) $(INCLUDES) -OBJ = commands.obj getopt_long.obj info.obj main.obj options.obj read_config.obj sound.obj sound_aiff.obj sound_file.obj sound_null.obj sound_wav.obj sound_dart.obj terminal.obj usleep.obj +OBJ = commands.obj delay.obj getopt_long.obj info.obj main.obj options.obj read_config.obj sound.obj sound_aiff.obj sound_file.obj sound_null.obj sound_wav.obj sound_dart.obj terminal.obj all: $(AOUT) $(AOUT): $(OBJ) wlink N $(AOUT) SYS OS2V2 OP QUIET LIBR {$(LIBS)} F {$(OBJ)} -.c: src;src/watcom +.c: src .c.obj: $(COMPILE) -fo=$^@ $< diff --git a/Makefile.w32 b/Makefile.w32 index 186178f..adbf122 100644 --- a/Makefile.w32 +++ b/Makefile.w32 @@ -32,14 +32,14 @@ CFLAGS+= -5s AOUT=xmp.exe COMPILE=$(CC) $(CFLAGS) $(CPPFLAGS) $(INCLUDES) -OBJ = commands.obj getopt_long.obj info.obj main.obj options.obj read_config.obj sound.obj sound_aiff.obj sound_file.obj sound_null.obj sound_wav.obj sound_win32.obj terminal.obj usleep.obj +OBJ = commands.obj delay.obj getopt_long.obj info.obj main.obj options.obj read_config.obj sound.obj sound_aiff.obj sound_file.obj sound_null.obj sound_wav.obj sound_win32.obj terminal.obj all: $(AOUT) $(AOUT): $(OBJ) wlink N $(AOUT) SYS NT OP QUIET LIBR {$(LIBS)} F {$(OBJ)} -.c: src;src/win32 +.c: src .c.obj: $(COMPILE) -fo=$^@ $< diff --git a/configure.ac b/configure.ac index 54215fc..64db985 100644 --- a/configure.ac +++ b/configure.ac @@ -96,7 +96,7 @@ AC_DEFUN([AC_CHECK_DEFINED],[ AS_VAR_POPDEF([ac_var])dnl ]) -AC_CHECK_HEADERS([getopt.h signal.h sys/time.h sys/audioio.h]) +AC_CHECK_HEADERS([getopt.h signal.h sys/select.h sys/time.h sys/audioio.h]) case $host_os in dnl don't check half-baked termios for amiga or dos targets. amigaos*|aros*|morphos*|*djgpp) ;; @@ -265,6 +265,6 @@ XMP_TRY_COMPILE(whether compiler understands -Wunused-result, int main(){}], CFLAGS="${CFLAGS} -Wno-unused-result") -AC_CHECK_FUNCS(kill getopt_long) +AC_CHECK_FUNCS(kill getopt_long usleep select) AC_CONFIG_FILES([Makefile src/Makefile]) AC_OUTPUT diff --git a/src/Makefile.am b/src/Makefile.am index afb0086..95e74ca 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -7,8 +7,8 @@ AM_CFLAGS = -Wall bin_PROGRAMS = xmp xmp_SOURCES = \ - commands.c common.h getopt_long.h list.h getopt_long.c info.c main.c \ - options.c read_config.c sound.c sound.h sound_file.c sound_null.c \ + commands.c common.h delay.c getopt_long.h list.h getopt_long.c info.c \ + main.c options.c read_config.c sound.c sound.h sound_file.c sound_null.c \ sound_wav.c sound_aiff.c terminal.c xmp_LDADD = ${LIBXMP_LIBS} xmp_LDFLAGS = ${XMP_DARWIN_LDFLAGS} @@ -96,5 +96,4 @@ pkgsysconfdir = ${sysconfdir}/${PACKAGE_NAME} pkgsysconf_DATA = modules.conf xmp.conf EXTRA_DIST = ${man_MANS} ${pkgsysconf_DATA} \ - win32/usleep.c win32/unistd.h \ - watcom/usleep.c watcom/unistd.h + win32/unistd.h watcom/unistd.h diff --git a/src/common.h b/src/common.h index 7e82012..53e9372 100644 --- a/src/common.h +++ b/src/common.h @@ -77,6 +77,8 @@ extern struct player_mode pmode[]; int report(char *, ...); +void delay_ms(int msec); + /* option */ void get_options(int, char **, struct options *); int read_config(struct options *); diff --git a/src/delay.c b/src/delay.c new file mode 100644 index 0000000..be23850 --- /dev/null +++ b/src/delay.c @@ -0,0 +1,61 @@ +/* Extended Module Player + * Copyright (C) 1996-2016 Claudio Matsuoka and Hipolito Carraro Jr + * + * This file is part of the Extended Module Player and is distributed + * under the terms of the GNU General Public License. See the COPYING + * file for more information. + */ + +#if defined(_WIN32) +#include + +void delay_ms(int msec) { + Sleep(msec); +} + +#elif defined(__OS2__) +#define INCL_DOSPROCESS +#include + +void delay_ms(int msec) { + DosSleep(msec); +} + +#elif defined(_DOS) +#include + +void delay_ms(int msec) { + delay(msec); /* doesn't seem to use int 15h. */ +} + +#elif defined(HAVE_USLEEP) +#include + +void delay_ms(int msec) { + usleep(msec * 1000); +} + +#elif defined(HAVE_SELECT) + +#ifdef HAVE_SYS_SELECT_H +# include +#else +# include +# include +# include +#endif +#include + +void delay_ms(int msec) { + struct timeval tv; + long usec; + + usec = msec * 1000; + tv.tv_sec = usec / 1000000; + tv.tv_usec = usec % 1000000; + select(0, NULL, NULL, NULL, &tv); +} + +#else +#error Missing implementation of delay_ms() +#endif diff --git a/src/main.c b/src/main.c index b6cbb02..b90d562 100644 --- a/src/main.c +++ b/src/main.c @@ -158,7 +158,7 @@ static void check_pause(xmp_context xc, struct control *ctl, info_frame(mi, fi, ctl, 1); } while (ctl->pause) { - usleep(100000); + delay_ms(100); read_command(xc, mi, ctl); if (ctl->display) { if (verbose) { diff --git a/src/sound_coreaudio.c b/src/sound_coreaudio.c index 581fe70..9e11088 100644 --- a/src/sound_coreaudio.c +++ b/src/sound_coreaudio.c @@ -10,7 +10,6 @@ #include #include #include -#include #include "sound.h" static AudioUnit au; @@ -230,7 +229,7 @@ static void play(void *b, int i) /* block until we have enough free space in the buffer */ while (buf_free() < i) - usleep(100000); + delay_ms(100); while (i) { if ((j = write_buffer(b, i)) > 0) { diff --git a/src/watcom/unistd.h b/src/watcom/unistd.h index 0d064c1..77496de 100644 --- a/src/watcom/unistd.h +++ b/src/watcom/unistd.h @@ -3,6 +3,4 @@ #include /* do not want Watcom unistd.h */ -void usleep (unsigned long usec); - #endif diff --git a/src/watcom/usleep.c b/src/watcom/usleep.c deleted file mode 100644 index 6c9afb1..0000000 --- a/src/watcom/usleep.c +++ /dev/null @@ -1,14 +0,0 @@ -#ifdef __OS2__ -#define INCL_DOSPROCESS -#include -void usleep (unsigned long usec) { - DosSleep (usec / 1000); -} -#endif - -#ifdef _DOS -#include -void usleep (unsigned long usec) { - delay (usec / 1000); /* doesn't seem to use int 15h. */ -} -#endif diff --git a/src/win32/unistd.h b/src/win32/unistd.h index 71942b6..e003449 100644 --- a/src/win32/unistd.h +++ b/src/win32/unistd.h @@ -3,6 +3,4 @@ #include -void usleep(long usec); - #endif diff --git a/src/win32/usleep.c b/src/win32/usleep.c deleted file mode 100644 index 3c24a9d..0000000 --- a/src/win32/usleep.c +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef HAVE_USLEEP - -#ifdef HAVE_SELECT - -#ifdef HAVE_SYS_SELECT_H -# include -#else -# include -# include -# include -#endif - -void usleep(long usec) -{ - struct timeval tv; - - tv.tv_sec = usec / 1000000; - tv.tv_usec = usec % 1000000; - select(0, NULL, NULL, NULL, &tv); -} - -#elif defined(_WIN32) - -/* usleep implementation from FreeSCI */ - -#include - -void usleep (long usec) -{ - LARGE_INTEGER lFrequency; - LARGE_INTEGER lEndTime; - LARGE_INTEGER lCurTime; - - QueryPerformanceFrequency (&lFrequency); - if (lFrequency.QuadPart) { - QueryPerformanceCounter (&lEndTime); - lEndTime.QuadPart += (LONGLONG) usec * - lFrequency.QuadPart / 1000000; - do { - QueryPerformanceCounter (&lCurTime); - Sleep(0); - } while (lCurTime.QuadPart < lEndTime.QuadPart); - } -} - -#endif - -#endif /* !HAVE_USLEEP */ diff --git a/vc/xmp.vcproj b/vc/xmp.vcproj index fbc62d9..9f69c6e 100644 --- a/vc/xmp.vcproj +++ b/vc/xmp.vcproj @@ -115,6 +115,10 @@ RelativePath="..\src\commands.c" > + + @@ -159,10 +163,6 @@ RelativePath="..\src\terminal.c" > - -