summaryrefslogtreecommitdiff
path: root/thread.h
blob: b69801a096d0a2446e0cd07b82f8f1f9e1da42f9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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