Permalink
Browse files

-CodeChange: Fix WIN32 code with SDL or SDL2

fixes #281
  • Loading branch information...
miniupnp committed Nov 3, 2017
1 parent c3027c5 commit a30a8cc25e1964e318211f6097ff7cf0b74ec68d
Showing with 22 additions and 14 deletions.
  1. +1 −9 source.list
  2. +2 −0 src/file.h
  3. +1 −1 src/os/sleep.h
  4. +16 −2 src/timer.c
  5. +2 −2 src/timer.h
View
@@ -87,15 +87,7 @@ opendune.c
os/endian.c
#if WIN32
os/error_win32.c
#if SDL
os/thread_sdl.c
#else
#if SDL2
os/thread_sdl.c
#else
os/thread_win32.c
#endif
#endif
os/thread_win32.c
os/readdir_win32.c
#else
#if OSX
View
@@ -3,6 +3,8 @@
#ifndef FILE_H
#define FILE_H
#include <stdio.h>
enum {
FILE_MODE_READ = 0x01,
FILE_MODE_WRITE = 0x02,
View
@@ -19,7 +19,7 @@
#define msleep(x) usleep(x * 1000)
#endif /* _WIN32 */
#if defined(_WIN32)
#if defined(_WIN32) && !defined(WITH_SDL) && !defined(WITH_SDL2)
#define sleepIdle() msleep(1)
#else /* _WIN32 */
#include "../timer.h"
View
@@ -133,8 +133,13 @@ void SleepAndProcessBackgroundTasks(void)
Timer_InterruptRun(0);
}
#elif !defined(_WIN32)
#elif !defined(_WIN32) || defined(WITH_SDL) || defined(WITH_SDL2)
#if defined(_WIN32)
static volatile int s_timer_count = 0;
#else
/* POSIX */
static volatile sig_atomic_t s_timer_count = 0;
#endif
static void Timer_Handler(int sig)
{
@@ -147,9 +152,14 @@ static void Timer_Handler(int sig)
void SleepAndProcessBackgroundTasks(void)
{
while (s_timer_count == 0) {
#if defined(_WIN32)
Sleep(2); /* TODO : use a semaphore */
#else
/* POSIX */
pause(); /* wait for a signal to happen */
/* another signal can have been triggered,
* ASLA sound is using SIGIO for triggering callbacks */
* ALSA sound is using SIGIO for triggering callbacks */
#endif
}
/* timer signal SIGALRM has been triggered */
if (s_timer_count > 1) {
@@ -172,7 +182,11 @@ void CALLBACK Timer_InterruptWindows(LPVOID arg, BOOLEAN TimerOrWaitFired) {
VARIABLE_NOT_USED(TimerOrWaitFired);
SuspendThread(s_timerMainThread);
#if defined(WITH_SDL) || defined(WITH_SDL2)
s_timer_count++;
#else
Timer_InterruptRun(0);
#endif /* defined(WITH_SDL) || defined(WITH_SDL2) */
ResumeThread(s_timerMainThread);
}
#endif /* _WIN32 */
View
@@ -28,8 +28,8 @@ extern void Timer_Add(void (*callback)(void), uint32 usec_delay, bool callonce);
extern void Timer_Change(void (*callback)(void), uint32 usec_delay);
extern void Timer_Remove(void (*callback)(void));
#if !defined(_WIN32)
#if !defined(_WIN32) || defined(WITH_SDL) || defined(WITH_SDL2)
extern void SleepAndProcessBackgroundTasks(void);
#endif /* _WIN32 */
#endif /* !_WIN32 || SDL || SDL2 */
#endif /* TIMER_H */

0 comments on commit a30a8cc

Please sign in to comment.