Skip to content

Instantly share code, notes, and snippets.

@bazhenovc
Last active September 23, 2015 11:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bazhenovc/f34d957de1a37f4847c0 to your computer and use it in GitHub Desktop.
Save bazhenovc/f34d957de1a37f4847c0 to your computer and use it in GitHub Desktop.
class Thread
{
private:
uint8_t storage[kThreadDataStorage];
public:
typedef void (*ThreadWorkerFunction)(void*);
void StartWorkerFunction(ThreadWorkerFunction func);
template <typename F, typename ...Args>
inline void Start(F&& func, Args&&... args)
{
typedef Function<void()> FunctionType;
FunctionType* fn = new (storage) FunctionType([&]() { func(std::forward<Args>(args)...); })
StartWorkerFunction([](void* arg) {
FunctionType* self = reinterpret_cast<FunctionType*>(arg);
(*self)();
}, fn);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment