37 lines
689 B
C++
37 lines
689 B
C++
#ifndef THREAD_WRAPPER_HPP
|
|
#define THREAD_WRAPPER_HPP
|
|
|
|
#include <cstddef>
|
|
|
|
namespace app {
|
|
|
|
template <typename ThreadType> class ThreadWrapper {
|
|
public:
|
|
/**
|
|
* @brief Entry point to thread. Must define init(), run(), and finalize() for
|
|
* thread type.
|
|
*
|
|
*/
|
|
inline static void entryPoint(void *, void *, void *) {
|
|
auto thread = ThreadType();
|
|
thread.init();
|
|
|
|
while (true) {
|
|
thread.run();
|
|
thread.incrementRunCount();
|
|
}
|
|
|
|
// NOTE: Maybe one day I'll add logic to be able to finalize a thread...
|
|
thread.finalize();
|
|
}
|
|
|
|
private:
|
|
inline void incrementRunCount() { ++runCounter_; }
|
|
|
|
std::size_t runCounter_ = 0;
|
|
};
|
|
|
|
} // namespace app
|
|
|
|
#endif
|