diff options
author | Vegard Storheil Eriksen <zyp@jvnv.net> | 2011-03-31 13:52:25 +0200 |
---|---|---|
committer | Vegard Storheil Eriksen <zyp@jvnv.net> | 2011-03-31 13:52:25 +0200 |
commit | 02ad565b49c916d9e1ca83c2486e6b0e388eb8e8 (patch) | |
tree | 924f5543c76c1d32c1d30e79c5de7b524f9718a5 /thread.h |
Initial import.
Diffstat (limited to 'thread.h')
-rw-r--r-- | thread.h | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/thread.h b/thread.h new file mode 100644 index 0000000..b69801a --- /dev/null +++ b/thread.h @@ -0,0 +1,23 @@ +#ifndef THREAD_H +#define THREAD_H + +#include <ch.h> + +#define noreturn_t __attribute__((noreturn)) void + +template<class Child, size_t stack_size> +class BaseThread { + private: + WORKING_AREA(stack_space, stack_size); + + static inline noreturn_t thread_main_wrap(void* arg) { + ((Child*)arg)->thread_main(); + } + + public: + void start(tprio_t priority = NORMALPRIO) { + chThdCreateStatic(stack_space, sizeof(stack_space), priority, (tfunc_t)thread_main_wrap, this); + } +}; + +#endif |