Browse Source

GOS updates to fix compile warnings on linux

remotes/origin_old/ugfx_release_2.6
inmarket 8 years ago
parent
commit
2776d00e82
  1. 23
      src/gos/gfx_linux.c
  2. 2
      src/gos/gfx_linux.h
  3. 11
      src/gos/gfx_osx.c

23
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) {

2
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);

11
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.

Loading…
Cancel
Save