14 #include <QElapsedTimer>
16 extern "C" void _gosPostInit(
void);
18 class Thread :
public QThread
21 typedef gThreadreturn (*fptr)(
void* param);
23 void setFunction(fptr
function,
void* param)
29 gThreadreturn returnValue()
34 virtual void run()
override
40 _returnValue = _function(_param);
46 gThreadreturn _returnValue;
49 static QElapsedTimer _systickTimer;
50 static QMutex _systemMutex;
54 _systickTimer.start();
57 void _gosPostInit(
void)
90 void*
gfxRealloc(
void* ptr, gMemSize oldsz, gMemSize newsz)
93 return realloc(ptr, newsz);
118 return _systickTimer.elapsed();
133 _systemMutex.unlock();
138 *pmutex =
new QMutex;
143 delete static_cast<QMutex*
>(*pmutex);
148 static_cast<QMutex*
>(*pmutex)->lock();
153 static_cast<QMutex*
>(*pmutex)->unlock();
158 *psem =
new QSemaphore(limit);
160 static_cast<QSemaphore*
>(*psem)->release(val);
165 delete static_cast<QSemaphore*
>(*psem);
170 return static_cast<QSemaphore*
>(*psem)->tryAcquire(1, ms);
175 return static_cast<QSemaphore*
>(*psem)->tryAcquire(1);
180 static_cast<QSemaphore*
>(*psem)->release(1);
185 static_cast<QSemaphore*
>(*psem)->release(1);
192 Thread* thread =
new Thread;
193 thread->setFunction(fn, param);
195 thread->setStackSize(stacksz);
197 thread->start(
static_cast<QThread::Priority
>(prio));
199 return static_cast<gThread>(thread);
204 Thread* t =
static_cast<Thread*
>(thread);
206 gThreadreturn returnValue = t->returnValue();
215 return static_cast<Thread*
>(QThread::currentThread());
220 static_cast<Thread*
>(thread)->exit();
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.
gTicks gfxMillisecondsToTicks(gDelay ms)
Convert a given number of millseconds to a number of operating system ticks.
gBool gfxSemWait(gSem *psem, gDelay ms)
Wait on a semaphore.
void gfxExit(void)
Exit the GFX application.
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.
gThread gfxThreadMe(void)
Get the current thread handle.
void * gfxAlloc(gMemSize sz)
Allocate memory.
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.
gBool gfxSemWaitI(gSem *psem)
Test if a wait on a semaphore can be satisfied immediately.
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 * gfxRealloc(void *ptr, gMemSize oldsz, gMemSize newsz)
Re-allocate memory.
void gfxMutexDestroy(gMutex *pmutex)
Destroy a Mutex.
void gfxFree(void *ptr)
Free memory.
void gfxSemSignalI(gSem *psem)
Signal a semaphore.
void gfxSleepMilliseconds(gDelay ms)
Put the current thread to sleep for the specified period in milliseconds.
void gfxThreadClose(gThread thread)
Close the thread handle.