diff options
Diffstat (limited to 'src/gos')
-rw-r--r-- | src/gos/gfx_linux.c | 23 | ||||
-rw-r--r-- | src/gos/gfx_linux.h | 2 | ||||
-rw-r--r-- | src/gos/gfx_osx.c | 11 |
3 files changed, 28 insertions, 8 deletions
diff --git a/src/gos/gfx_linux.c b/src/gos/gfx_linux.c index 59b7f9c8..fc716ec9 100644 --- a/src/gos/gfx_linux.c +++ b/src/gos/gfx_linux.c @@ -9,10 +9,20 @@ #if GFX_USE_OS_LINUX +// Linux seems to have deprecated pthread_yield() and now says to use sched_yield() +#define USE_SCHED_NOT_PTHREAD_YIELD TRUE + #include <stdio.h> #include <unistd.h> #include <errno.h> +#include <sys/time.h> #include <time.h> +#if USE_SCHED_NOT_PTHREAD_YIELD + #include <sched.h> + #define linuxyield() sched_yield() +#else + #define linuxyield() pthread_yield() +#endif static gfxMutex SystemMutex; @@ -35,6 +45,10 @@ void gfxSystemUnlock(void) { gfxMutexExit(&SystemMutex); } +void gfxYield(void) { + linuxyield(); +} + void gfxHalt(const char *msg) { if (msg) fprintf(stderr, "%s\n", msg); @@ -46,7 +60,7 @@ void gfxSleepMilliseconds(delaytime_t ms) { switch(ms) { case TIME_IMMEDIATE: - pthread_yield(); + linuxyield(); return; case TIME_INFINITE: @@ -67,7 +81,7 @@ void gfxSleepMicroseconds(delaytime_t ms) { switch(ms) { case TIME_IMMEDIATE: - pthread_yield(); + linuxyield(); return; case TIME_INFINITE: @@ -93,6 +107,9 @@ systemticks_t gfxSystemTicks(void) { gfxThreadHandle gfxThreadCreate(void *stackarea, size_t stacksz, threadpriority_t prio, DECLARE_THREAD_FUNCTION((*fn),p), void *param) { gfxThreadHandle th; + (void) stackarea; + (void) stacksz; + (void) prio; // Implementing priority with pthreads is a rats nest that is also pthreads implementation dependent. // Only some pthreads schedulers support it, some implementations use the operating system process priority mechanisms. @@ -151,7 +168,7 @@ bool_t gfxSemWait(gfxSem *pSem, delaytime_t ms) { struct timeval now; struct timespec tm; - gettimeofday(&now); + gettimeofday(&now, 0); tm.tv_sec = now.tv_sec + ms / 1000; tm.tv_nsec = (now.tv_usec + ms % 1000) * 1000; while (!pSem->cnt) { diff --git a/src/gos/gfx_linux.h b/src/gos/gfx_linux.h index 9ead9c0e..bd31184e 100644 --- a/src/gos/gfx_linux.h +++ b/src/gos/gfx_linux.h @@ -34,7 +34,6 @@ typedef pthread_mutex_t gfxMutex; #define gfxRealloc(p,osz,nsz) realloc(p, nsz) #define gfxFree(ptr) free(ptr) #define gfxMillisecondsToTicks(ms) (ms) -#define gfxYield() pthread_yield() #define gfxThreadMe() pthread_self() #define gfxThreadClose(th) (void)th #define gfxMutexInit(pmtx) pthread_mutex_init(pmtx, 0) @@ -67,6 +66,7 @@ typedef struct gfxSem { extern "C" { #endif +void gfxYield(void); void gfxHalt(const char *msg); void gfxSleepMilliseconds(delaytime_t ms); void gfxSleepMicroseconds(delaytime_t ms); diff --git a/src/gos/gfx_osx.c b/src/gos/gfx_osx.c index 50b06530..f2e58f77 100644 --- a/src/gos/gfx_osx.c +++ b/src/gos/gfx_osx.c @@ -30,7 +30,7 @@ void get_ticks(mach_timespec_t *mts){ clock_get_time(cclock, mts); mach_port_deallocate(mach_task_self(), cclock); - + } void _gosInit(void) @@ -89,16 +89,19 @@ void gfxSleepMicroseconds(delaytime_t ms) { systemticks_t gfxSystemTicks(void) { //struct timespec ts; //clock_gettime(CLOCK_MONOTONIC, &ts); - + mach_timespec_t ts; get_ticks(&ts); - - + + return ts.tv_sec * 1000UL + ts.tv_nsec / 1000UL; } gfxThreadHandle gfxThreadCreate(void *stackarea, size_t stacksz, threadpriority_t prio, DECLARE_THREAD_FUNCTION((*fn),p), void *param) { gfxThreadHandle th; + (void) stackarea; + (void) stacksz; + (void) prio; // Implementing priority with pthreads is a rats nest that is also pthreads implementation dependent. // Only some pthreads schedulers support it, some implementations use the operating system process priority mechanisms. |