Last active
September 23, 2015 11:19
-
-
Save bazhenovc/f34d957de1a37f4847c0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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