µGFX  2.9
version 2.9
gos_linux.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_LINUX_H
9 #define _GOS_LINUX_H
10 
11 #if GFX_USE_OS_LINUX
12 
13 // We don't put this in the general sys_options.h as it is Linux specific.
14 #ifndef GFX_USE_POSIX_SEMAPHORES
15  #define GFX_USE_POSIX_SEMAPHORES GFXON
16 #endif
17 
18 #include <sys/types.h>
19 #include <stdlib.h>
20 #include <pthread.h>
21 
22 #if GFX_USE_POSIX_SEMAPHORES
23  #include <semaphore.h>
24 #endif
25 
26 typedef unsigned long gTicks;
27 typedef void * gThreadreturn;
28 typedef unsigned long gDelay;
29 typedef pthread_t gThread;
30 typedef int gThreadpriority;
31 typedef gU32 gSemcount;
32 typedef pthread_mutex_t gMutex;
33 
34 #define GFX_THREAD_FUNCTION(fnName, param) gThreadreturn fnName(void *param)
35 #define GFX_THREAD_STACK(name, sz) gU8 name[0];
36 #define gfxThreadReturn(retval) return retval
37 
38 #define gfxExit() exit(0)
39 #define gfxAlloc(sz) malloc(sz)
40 #define gfxRealloc(p,osz,nsz) realloc(p, nsz)
41 #define gfxFree(ptr) free(ptr)
42 #define gfxMillisecondsToTicks(ms) (ms)
43 #define gfxThreadMe() pthread_self()
44 #define gfxThreadClose(th) (void)th
45 #define gfxMutexInit(pmtx) pthread_mutex_init(pmtx, 0)
46 #define gfxMutexDestroy(pmtx) pthread_mutex_destroy(pmtx)
47 #define gfxMutexEnter(pmtx) pthread_mutex_lock(pmtx)
48 #define gfxMutexExit(pmtx) pthread_mutex_unlock(pmtx)
49 #define gfxSemWaitI(psem) gfxSemWait(psem, gDelayNone)
50 #define gfxSemSignalI(psem) gfxSemSignal(psem)
51 
52 #define gDelayNone 0
53 #define gDelayForever ((gDelay)-1)
54 #define gSemMaxCount ((gSemcount)-1)
55 #define gThreadpriorityLow 10
56 #define gThreadpriorityNormal 0
57 #define gThreadpriorityHigh -10
58 
59 #if GFX_USE_POSIX_SEMAPHORES
60  typedef struct gSem {
61  sem_t sem;
62  gSemcount max;
63  } gSem;
64 #else
65  typedef struct gSem {
66  pthread_mutex_t mtx;
67  pthread_cond_t cond;
68  gSemcount cnt;
69  gSemcount max;
70  } gSem;
71 #endif
72 
73 /*===========================================================================*/
74 /* Function declarations. */
75 /*===========================================================================*/
76 
77 void gfxYield(void);
78 void gfxHalt(const char *msg);
79 void gfxSleepMilliseconds(gDelay ms);
80 void gfxSleepMicroseconds(gDelay ms);
81 gTicks gfxSystemTicks(void);
82 void gfxSystemLock(void);
83 void gfxSystemUnlock(void);
84 void gfxSemInit(gSem *psem, gSemcount val, gSemcount limit);
85 void gfxSemDestroy(gSem *psem);
86 gBool gfxSemWait(gSem *psem, gDelay ms);
87 void gfxSemSignal(gSem *psem);
88 gThread gfxThreadCreate(void *stackarea, gMemSize stacksz, gThreadpriority prio, GFX_THREAD_FUNCTION((*fn),p), void *param);
89 gThreadreturn gfxThreadWait(gThread thread);
90 
91 #endif /* GFX_USE_OS_LINUX */
92 
93 #endif /* _GOS_LINUX_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.
void gfxYield(void)
Yield the current thread.
#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