9 #define GFILE_NEED_STDIO_MUST_BE_OFF
11 #include "../../gfx.h"
22 #include <mach/clock.h>
23 #include <mach/mach.h>
33 void _gosPostInit(
void)
52 fprintf(stderr,
"%s\n", msg);
61 case gDelayForever:
while(1) sleep(60);
return;
63 ts.tv_sec = ms / 1000;
64 ts.tv_nsec = (ms % 1000) * 1000000;
75 case gDelayForever:
while(1) sleep(60);
return;
77 ts.tv_sec = us / 1000000;
78 ts.tv_nsec = (us % 1000000) * 1000;
88 host_get_clock_service(mach_host_self(), SYSTEM_CLOCK, &cclock);
89 clock_get_time(cclock, &ts);
90 mach_port_deallocate(mach_task_self(), cclock);
92 return ts.tv_sec * 1000UL + ts.tv_nsec / 1000000;
108 if (pthread_create(&th, 0, fn, param))
114 gThreadreturn retval;
116 if (pthread_join(thread, &retval))
122 pthread_mutex_init(&pSem->mtx, 0);
123 pthread_cond_init(&pSem->cond, 0);
124 pthread_mutex_lock(&pSem->mtx);
127 pthread_mutex_unlock(&pSem->mtx);
131 pthread_mutex_destroy(&pSem->mtx);
132 pthread_cond_destroy(&pSem->cond);
136 pthread_mutex_lock(&pSem->mtx);
140 pthread_cond_wait(&pSem->cond, &pSem->mtx);
144 pthread_mutex_unlock(&pSem->mtx);
153 gettimeofday(&now, 0);
154 tm.tv_sec = now.tv_sec + ms / 1000;
155 tm.tv_nsec = now.tv_usec * 1000 + (ms % 1000) * 1000000;
161 if (pthread_cond_timedwait(&pSem->cond, &pSem->mtx, &tm)) {
162 pthread_mutex_unlock(&pSem->mtx);
170 pthread_mutex_unlock(&pSem->mtx);
175 pthread_mutex_lock(&pSem->mtx);
176 if (pSem->cnt < pSem->max) {
178 pthread_cond_signal(&pSem->cond);
180 pthread_mutex_unlock(&pSem->mtx);
gThreadreturn gfxThreadWait(gThread thread)
Wait for a thread to finish.
void gfxSemSignal(gSem *psem)
Signal a semaphore.
void * gThread
A thread handle.
gTicks gfxSystemTicks(void)
Get the current operating system tick time.
void gfxYield(void)
Yield the current thread.
#define GFX_THREAD_FUNCTION(fnName, param)
Declare a thread function.
void gfxMutexExit(gMutex *pmutex)
Exit the critical code region protected by the mutex.
gBool gfxSemWait(gSem *psem, gDelay ms)
Wait on a semaphore.
void gfxSystemUnlock(void)
Unlock the operating system previous locked by gfxSystemLock()
void gfxSleepMicroseconds(gDelay us)
Put the current thread to sleep for the specified period in microseconds.
void gfxMutexEnter(gMutex *pmutex)
Enter the critical code region protected by the mutex.
void gfxSystemLock(void)
Lock the operating system to protect a sequence of code.
void gfxMutexInit(gMutex *pmutex)
Initialise a mutex to protect a region of code from other threads.
gThread gfxThreadCreate(void *stackarea, gMemSize stacksz, gThreadpriority prio, GFX_THREAD_FUNCTION((*fn), p), void *param)
Start a new thread.
void gfxHalt(const char *msg)
Halt the GFX application due to an error.
void gfxSemDestroy(gSem *psem)
Destroy a Counted Semaphore.
void gfxSemInit(gSem *psem, gSemcount val, gSemcount limit)
Initialise a Counted Semaphore.
void gfxSleepMilliseconds(gDelay ms)
Put the current thread to sleep for the specified period in milliseconds.