Thread 일부 구현
This commit is contained in:
@@ -5,4 +5,34 @@
|
||||
|
||||
#else
|
||||
#error "이 플랫폼은 지원되지 않습니다."
|
||||
#endif
|
||||
#endif
|
||||
#include <functional>
|
||||
|
||||
namespace Chattr {
|
||||
|
||||
|
||||
class Thread {
|
||||
public:
|
||||
#ifdef _WIN32
|
||||
static DWORD WINAPI __thread(LPVOID param) {
|
||||
std::unique_ptr<std::function<void()>> func(reinterpret_cast<std::function<void()>*>(param));
|
||||
(*func)();
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
template<typename Callable, typename... Args>
|
||||
Thread(Callable&& f, Args&&... args);
|
||||
};
|
||||
|
||||
template<typename Callable, typename... Args>
|
||||
Thread::Thread(Callable&& f, Args&&... args) {
|
||||
auto boundFunc = std::bind(std::forward<Callable>(f), std::forward<Args>(args)...);
|
||||
|
||||
auto funcPtr = new std::function<void()>(boundFunc);
|
||||
|
||||
#ifdef _WIN32
|
||||
CreateThread(nullptr, 0, __thread, funcPtr, 0, nullptr);
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace Chattr
|
||||
Reference in New Issue
Block a user