Thread 일부 구현
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
#include "Socket/TCPSocket.hpp"
|
#include "Socket/TCPSocket.hpp"
|
||||||
#include "Socket/Log.hpp"
|
#include "Socket/Log.hpp"
|
||||||
#include "Utils/ConfigManager.hpp"
|
#include "Utils/ConfigManager.hpp"
|
||||||
|
#include "Utils/Thread.hpp"
|
||||||
|
|
||||||
#include "precomp.hpp"
|
#include "precomp.hpp"
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
@@ -37,6 +39,10 @@ int main() {
|
|||||||
else
|
else
|
||||||
clientAddr.length = sizeof(sockaddr_in6);
|
clientAddr.length = sizeof(sockaddr_in6);
|
||||||
|
|
||||||
|
Chattr::Thread t1([]() {
|
||||||
|
spdlog::info("thread?");
|
||||||
|
});
|
||||||
|
|
||||||
spdlog::info("Waiting for connection...");
|
spdlog::info("Waiting for connection...");
|
||||||
sock.accept(clientSock, clientAddr);
|
sock.accept(clientSock, clientAddr);
|
||||||
}
|
}
|
||||||
2
impl/Utils/Thread.cpp
Normal file
2
impl/Utils/Thread.cpp
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
#include "Utils/Thread.hpp"
|
||||||
|
|
||||||
@@ -5,4 +5,34 @@
|
|||||||
|
|
||||||
#else
|
#else
|
||||||
#error "이 플랫폼은 지원되지 않습니다."
|
#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