version 2.8
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.org/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 <stdint.h>
15 #include <pthread.h>
16 #include <stdlib.h>
17 
18 /* Already defined int8_t, uint8_t, int16_t, uint16_t, int32_t, uint32_t, size_t */
19 
20 typedef int8_t bool_t;
21 typedef unsigned long systemticks_t;
22 typedef void * threadreturn_t;
23 typedef unsigned long delaytime_t;
24 typedef pthread_t gfxThreadHandle;
25 typedef int threadpriority_t;
26 typedef uint32_t semcount_t;
27 typedef pthread_mutex_t gfxMutex;
28 
29 #define DECLARE_THREAD_FUNCTION(fnName, param) threadreturn_t fnName(void *param)
30 #define DECLARE_THREAD_STACK(name, sz) uint8_t name[0];
31 #define THREAD_RETURN(retval) return retval
32 
33 #define gfxExit() exit(0)
34 #define gfxAlloc(sz) malloc(sz)
35 #define gfxRealloc(p,osz,nsz) realloc(p, nsz)
36 #define gfxFree(ptr) free(ptr)
37 #define gfxMillisecondsToTicks(ms) (ms)
38 #define gfxYield() sched_yield()
39 #define gfxThreadMe() pthread_self()
40 #define gfxThreadClose(th) (void)th
41 #define gfxMutexInit(pmtx) pthread_mutex_init(pmtx, 0)
42 #define gfxMutexDestroy(pmtx) pthread_mutex_destroy(pmtx)
43 #define gfxMutexEnter(pmtx) pthread_mutex_lock(pmtx)
44 #define gfxMutexExit(pmtx) pthread_mutex_unlock(pmtx)
45 #define gfxSemWaitI(psem) gfxSemWait(psem, TIME_IMMEDIATE)
46 #define gfxSemSignalI(psem) gfxSemSignal(psem)
47 
48 #define TIME_IMMEDIATE 0
49 #define TIME_INFINITE ((delaytime_t)-1)
50 #define MAX_SEMAPHORE_COUNT ((semcount_t)-1)
51 #define LOW_PRIORITY 10
52 #define NORMAL_PRIORITY 0
53 #define HIGH_PRIORITY -10
54 
55 typedef struct gfxSem {
56  pthread_mutex_t mtx;
57  pthread_cond_t cond;
58  semcount_t cnt;
59  semcount_t max;
60 } gfxSem;
61 
62 /*===========================================================================*/
63 /* Function declarations. */
64 /*===========================================================================*/
65 
66 #ifdef __cplusplus
67 extern "C" {
68 #endif
69 
70 void gfxHalt(const char *msg);
71 void gfxSleepMilliseconds(delaytime_t ms);
72 void gfxSleepMicroseconds(delaytime_t ms);
73 systemticks_t gfxSystemTicks(void);
74 void gfxSystemLock(void);
75 void gfxSystemUnlock(void);
76 void gfxSemInit(gfxSem *psem, semcount_t val, semcount_t limit);
77 void gfxSemDestroy(gfxSem *psem);
78 bool_t gfxSemWait(gfxSem *psem, delaytime_t ms);
79 void gfxSemSignal(gfxSem *psem);
80 gfxThreadHandle gfxThreadCreate(void *stackarea, size_t stacksz, threadpriority_t prio, DECLARE_THREAD_FUNCTION((*fn),p), void *param);
81 threadreturn_t gfxThreadWait(gfxThreadHandle thread);
82 
83 #ifdef __cplusplus
84 }
85 #endif
86 
87 #endif /* GFX_USE_OS_OSX */
88 #endif /* _GOS_OSX_H */
void * gfxThreadHandle
A thread handle.
Definition: gos.h:117
void gfxSemInit(gfxSem *psem, semcount_t val, semcount_t limit)
Initialise a Counted Semaphore.
systemticks_t gfxSystemTicks(void)
Get the current operating system tick time.
void gfxSemDestroy(gfxSem *psem)
Destroy a Counted Semaphore.
bool_t gfxSemWait(gfxSem *psem, delaytime_t ms)
Wait on a semaphore.
A semaphore.
Definition: gos.h:105
void gfxSystemLock(void)
Lock the operating system to protect a sequence of code.
#define DECLARE_THREAD_FUNCTION(fnName, param)
Declare a thread function.
Definition: gos.h:62
void gfxHalt(const char *msg)
Halt the GFX application due to an error.
void gfxSemSignal(gfxSem *psem)
Signal a semaphore.
void gfxSleepMicroseconds(delaytime_t us)
Put the current thread to sleep for the specified period in microseconds.
gfxThreadHandle gfxThreadCreate(void *stackarea, size_t stacksz, threadpriority_t prio, DECLARE_THREAD_FUNCTION((*fn), p), void *param)
Start a new thread.
A mutex.
Definition: gos.h:111
threadreturn_t gfxThreadWait(gfxThreadHandle thread)
Wait for a thread to finish.
void gfxSleepMilliseconds(delaytime_t ms)
Put the current thread to sleep for the specified period in milliseconds.
void gfxSystemUnlock(void)
Unlock the operating system previous locked by gfxSystemLock()