aboutsummaryrefslogtreecommitdiffstats
path: root/include/gos
diff options
context:
space:
mode:
Diffstat (limited to 'include/gos')
-rw-r--r--include/gos/chibios.h15
-rw-r--r--include/gos/gos.h51
-rw-r--r--include/gos/win32.h15
3 files changed, 66 insertions, 15 deletions
diff --git a/include/gos/chibios.h b/include/gos/chibios.h
index 1fa93141..280a9a45 100644
--- a/include/gos/chibios.h
+++ b/include/gos/chibios.h
@@ -51,21 +51,21 @@ typedef cnt_t semcount_t;
typedef msg_t threadreturn_t;
typedef tprio_t threadpriority_t;
-typedef threadreturn_t (*gfxThreadFunction)(void *param);
-
#define MAX_SEMAPHORE_COUNT ((semcount_t)(((unsigned long)((semcount_t)(-1))) >> 1))
#define LOW_PRIORITY LOWPRIO
#define NORMAL_PRIORITY NORMALPRIO
#define HIGH_PRIORITY HIGHPRIO
-#define DECLARESTACK(name, sz) WORKING_AREA(name, sz);
+#define DECLARE_THREAD_STACK(name, sz) WORKING_AREA(name, sz)
+#define DECLARE_THREAD_FUNCTION(fnName, param) threadreturn_t fnName(void *param)
typedef struct {
Semaphore sem;
semcount_t limit;
} gfxSem;
-#define gfxMutex Mutex
+typedef Mutex gfxMutex;
+typedef Thread * gfxThreadHandle;
/*===========================================================================*/
/* Function declarations. */
@@ -85,7 +85,7 @@ extern "C" {
#define gfxSystemLock() chSysLock()
#define gfxSystemUnlock() chSysUnlock()
#define gfxMutexInit(pmutex) chMtxInit(pmutex)
-#define gfxMutexDestroy(pmutex) ;
+#define gfxMutexDestroy(pmutex) {}
#define gfxMutexEnter(pmutex) chMtxLock(pmutex)
#define gfxMutexExit(pmutex) chMtxUnlock()
void gfxSleepMilliseconds(delaytime_t ms);
@@ -97,7 +97,10 @@ void gfxSemSignal(gfxSem *psem);
void gfxSemSignalI(gfxSem *psem);
#define gfxSemCounterI(psem) ((psem)->sem.s_cnt)
#define gfxSemCounter(psem) ((psem)->sem.s_cnt)
-bool_t gfxCreateThread(void *stackarea, size_t stacksz, threadpriority_t prio, gfxThreadFunction fn, void *param);
+gfxThreadHandle gfxThreadCreate(void *stackarea, size_t stacksz, threadpriority_t prio, DECLARE_THREAD_FUNCTION((*fn),p), void *param);
+#define gfxThreadWait(thread) chThdWait(thread)
+#define gfxThreadMe() chThdSelf()
+#define gfxThreadClose(thread) {}
#ifdef __cplusplus
}
diff --git a/include/gos/gos.h b/include/gos/gos.h
index d979cd27..177349cf 100644
--- a/include/gos/gos.h
+++ b/include/gos/gos.h
@@ -61,10 +61,15 @@
typedef short semcount_t;
typedef int threadreturn_t;
typedef int threadpriority_t;
+
/**
- * @brief A function for a new thread to execute.
+ * @brief Declare a thread stack and function
+ * @{
*/
- typedef threadreturn_t (*gfxThreadFunction)(void *param);
+ #define DECLARE_THREAD_FUNCTION(fnName, param) threadreturn_t fnName(void *param)
+ #define DECLARE_THREAD_STACK(name, sz) uint8_t name[sz];
+ /* @} */
+
/**
* @}
*
@@ -80,7 +85,6 @@
#define LOW_PRIORITY 0
#define NORMAL_PRIORITY 1
#define HIGH_PRIORITY 2
- #define DECLARESTACK(name, sz) uint8_t name[sz];
/* @} */
/**
@@ -95,6 +99,12 @@
*/
typedef struct {} gfxMutex;
+ /**
+ * @brief A thread handle
+ * @note Your operating system will have a proper definition for this.
+ */
+ typedef void * gfxThreadHandle;
+
/*===========================================================================*/
/* Function declarations. */
/*===========================================================================*/
@@ -355,7 +365,7 @@
/**
* @brief Start a new thread.
- * @return Return TRUE if the thread was started, FALSE on an error
+ * @return Returns a thread handle if the thread was started, NULL on an error
*
* @param[in] stackarea A pointer to the area for the new threads stack or NULL to dynamically allocate it
* @param[in] stacksz The size of the thread stack. 0 means the default operating system size although this
@@ -366,7 +376,38 @@
*
* @api
*/
- bool_t gfxCreateThread(void *stackarea, size_t stacksz, threadpriority_t prio, gfxThreadFunction fn, void *param);
+ gfxThreadHandle gfxThreadCreate(void *stackarea, size_t stacksz, threadpriority_t prio, DECLARE_THREAD_FUNCTION((*fn),p), void *param);
+
+ /**
+ * @brief Wait for a thread to finish.
+ * @return Returns the thread exit code.
+ *
+ * @param[in] thread The Thread Handle
+ *
+ * @note This will also close the thread handle as it is no longer useful
+ * once the thread has ended.
+ * @api
+ */
+ threadreturn_t gfxThreadWait(gfxThreadHandle thread);
+
+ /**
+ * @brief Get the current thread handle.
+ * @return A thread handle
+ *
+ * @api
+ */
+ gfxThreadHandle gfxThreadMe(void);
+
+ /**
+ * @brief Close the thread handle.
+ *
+ * @param[in] thread The Thread Handle
+ *
+ * @note This does not affect the thread, it just closes our handle to the thread.
+ *
+ * @api
+ */
+ void gfxThreadClose(gfxThreadHandle thread);
#ifdef __cplusplus
}
diff --git a/include/gos/win32.h b/include/gos/win32.h
index 80a1f430..d61de187 100644
--- a/include/gos/win32.h
+++ b/include/gos/win32.h
@@ -30,6 +30,9 @@
//#define WIN32_LEAN_AND_MEAN
#include <windows.h>
+/* Stop cygwin from defining these types */
+#define __int8_t_defined
+
/**
* size_t
* TRUE, FALSE
@@ -45,10 +48,11 @@ typedef unsigned __int32 uint32_t;
typedef DWORD delaytime_t;
typedef DWORD systemticks_t;
typedef LONG semcount_t;
-#define threadreturn_t DWORD WINAPI
+typedef DWORD threadreturn_t;
typedef int threadpriority_t;
-typedef threadreturn_t (*gfxThreadFunction)(void *param);
+#define DECLARE_THREAD_FUNCTION(fnName, param) threadreturn_t WINAPI fnName(void *param)
+#define DECLARE_THREAD_STACK(name, sz) uint8_t name[0];
#define TIME_IMMEDIATE 0
#define TIME_INFINITE INFINITE
@@ -56,10 +60,10 @@ typedef threadreturn_t (*gfxThreadFunction)(void *param);
#define LOW_PRIORITY THREAD_PRIORITY_BELOW_NORMAL
#define NORMAL_PRIORITY THREAD_PRIORITY_NORMAL
#define HIGH_PRIORITY THREAD_PRIORITY_ABOVE_NORMAL
-#define DECLARESTACK(name, sz) uint8_t name[0];
typedef HANDLE gfxSem;
typedef HANDLE gfxMutex;
+typedef HANDLE gfxThreadHandle;
#define gfxExit() ExitProcess(0)
#define gfxAlloc(sz) malloc(sz)
@@ -77,6 +81,8 @@ typedef HANDLE gfxMutex;
#define gfxSemSignal(psem) ReleaseSemaphore(*(psem), 1, NULL)
#define gfxSemSignalI(psem) ReleaseSemaphore(*(psem), 1, NULL)
#define gfxSemCounterI(psem) gfxSemCounter(psem)
+#define gfxThreadMe() GetCurrentThread()
+#define gfxThreadClose(thread) CloseHandle(thread)
/*===========================================================================*/
/* Function declarations. */
@@ -92,7 +98,8 @@ bool_t gfxSemWait(gfxSem *psem, delaytime_t ms);
semcount_t gfxSemCounter(gfxSem *pSem);
void gfxSystemLock(void);
void gfxSystemUnlock(void);
-bool_t gfxCreateThread(void *stackarea, size_t stacksz, threadpriority_t prio, gfxThreadFunction fn, void *param);
+gfxThreadHandle gfxThreadCreate(void *stackarea, size_t stacksz, threadpriority_t prio, DECLARE_THREAD_FUNCTION((*fn),p), void *param);
+threadreturn_t gfxThreadWait(gfxThreadHandle thread);
#ifdef __cplusplus
}