µGFX  2.9
version 2.9
gos_osx.h
1 /*
2  * This file is subject to the terms of the GFX License. If a copy of
3  * the license was not distributed with this file, you can obtain one at:
4  *
5  * http://ugfx.io/license.html
6  */
7 
8 #ifndef _GOS_OSX_H
9 #define _GOS_OSX_H
10 
11 #if GFX_USE_OS_OSX
12 
13 #include <sys/types.h>
14 #include <pthread.h>
15 #include <stdlib.h>
16 
17 typedef unsigned long gTicks;
18 typedef void * gThreadreturn;
19 typedef unsigned long gDelay;
20 typedef pthread_t gThread;
21 typedef int gThreadpriority;
22 typedef gU32 gSemcount;
23 typedef pthread_mutex_t gMutex;
24 
25 #define GFX_THREAD_FUNCTION(fnName, param) gThreadreturn fnName(void *param)
26 #define GFX_THREAD_STACK(name, sz) gU8 name[0];
27 #define gfxThreadReturn(retval) return retval
28 
29 #define gfxExit() exit(0)
30 #define gfxAlloc(sz) malloc(sz)
31 #define gfxRealloc(p,osz,nsz) realloc(p, nsz)
32 #define gfxFree(ptr) free(ptr)
33 #define gfxMillisecondsToTicks(ms) (ms)
34 #define gfxYield() sched_yield()
35 #define gfxThreadMe() pthread_self()
36 #define gfxThreadClose(th) (void)th
37 #define gfxMutexInit(pmtx) pthread_mutex_init(pmtx, 0)
38 #define gfxMutexDestroy(pmtx) pthread_mutex_destroy(pmtx)
39 #define gfxMutexEnter(pmtx) pthread_mutex_lock(pmtx)
40 #define gfxMutexExit(pmtx) pthread_mutex_unlock(pmtx)
41 #define gfxSemWaitI(psem) gfxSemWait(psem, gDelayNone)
42 #define gfxSemSignalI(psem) gfxSemSignal(psem)
43 
44 #define gDelayNone 0
45 #define gDelayForever ((gDelay)-1)
46 #define gSemMaxCount ((gSemcount)-1)
47 #define gThreadpriorityLow 10
48 #define gThreadpriorityNormal 0
49 #define gThreadpriorityHigh -10
50 
51 typedef struct gSem {
52  pthread_mutex_t mtx;
53  pthread_cond_t cond;
54  gSemcount cnt;
55  gSemcount max;
56 } gSem;
57 
58 /*===========================================================================*/
59 /* Function declarations. */
60 /*===========================================================================*/
61 
62 void gfxHalt(const char *msg);
63 void gfxSleepMilliseconds(gDelay ms);
64 void gfxSleepMicroseconds(gDelay ms);
65 gTicks gfxSystemTicks(void);
66 void gfxSystemLock(void);
67 void gfxSystemUnlock(void);
68 void gfxSemInit(gSem *psem, gSemcount val, gSemcount limit);
69 void gfxSemDestroy(gSem *psem);
70 gBool gfxSemWait(gSem *psem, gDelay ms);
71 void gfxSemSignal(gSem *psem);
72 gThread gfxThreadCreate(void *stackarea, gMemSize stacksz, gThreadpriority prio, GFX_THREAD_FUNCTION((*fn),p), void *param);
73 gThreadreturn gfxThreadWait(gThread thread);
74 
75 #endif /* GFX_USE_OS_OSX */
76 #endif /* _GOS_OSX_H */
gThreadreturn gfxThreadWait(gThread thread)
Wait for a thread to finish.
void gfxSemSignal(gSem *psem)
Signal a semaphore.
void * gThread
A thread handle.
Definition: gos.h:116
gTicks gfxSystemTicks(void)
Get the current operating system tick time.
#define GFX_THREAD_FUNCTION(fnName, param)
Declare a thread function.
Definition: gos.h:73
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 gfxSystemLock(void)
Lock the operating system to protect a sequence of code.
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.
A mutex.
Definition: gos.h:110
A semaphore.
Definition: gos.h:104