일단 iocp는 완성한 듯 윈도우에서만 되면 될 듯
This commit is contained in:
@@ -9,6 +9,9 @@
|
||||
#endif
|
||||
#include <functional>
|
||||
#include <future>
|
||||
#include <typeinfo>
|
||||
|
||||
#include "Socket/Log.hpp"
|
||||
|
||||
namespace Chattr {
|
||||
|
||||
@@ -40,7 +43,7 @@ public:
|
||||
(!std::is_void_v<std::invoke_result_t<_Callable, _Args...>>)
|
||||
Thread(_Callable&& __f, _Args&&... __args) {
|
||||
auto boundFunc = [this, __f, ... __args = std::move(__args)]() mutable {
|
||||
returnValuePtr = new std::invoke_result_t<_Callable, _Args...>(__f(std::move(__args)...));
|
||||
returnValuePtr = std::make_shared<std::invoke_result_t<_Callable, _Args...>>(__f(std::move(__args)...));
|
||||
};
|
||||
std::packaged_task<void()>* funcPtr = new std::packaged_task<void()>(std::move(boundFunc));
|
||||
#ifdef _WIN32
|
||||
@@ -60,8 +63,10 @@ public:
|
||||
#ifdef _WIN32
|
||||
handle_ = (HANDLE)_beginthreadex(nullptr, 0, thread_func, funcPtr, 0, nullptr);
|
||||
#elif __linux__
|
||||
pthread_create(&handle_, NULL, thread_func, funcPtr);
|
||||
int rc = pthread_create(&handle_, NULL, thread_func, funcPtr);
|
||||
#endif
|
||||
if (handle_ <= 0 || rc != 0)
|
||||
log::critical("pthread_create()");
|
||||
}
|
||||
~Thread();
|
||||
|
||||
@@ -69,7 +74,7 @@ public:
|
||||
#ifdef _WIN32
|
||||
WaitForSingleObject(handle_, INFINITE);
|
||||
#elif __linux__
|
||||
pthread_join(handle_, &returnValuePtr);
|
||||
pthread_join(handle_, nullptr);
|
||||
#endif
|
||||
}
|
||||
template<typename _RetType>
|
||||
@@ -78,7 +83,7 @@ public:
|
||||
#ifdef _WIN32
|
||||
WaitForSingleObject(handle_, INFINITE);
|
||||
#elif __linux__
|
||||
pthread_join(handle_, &returnValuePtr);
|
||||
pthread_join(handle_, nullptr);
|
||||
#endif
|
||||
return *static_cast<_RetType *>(returnValuePtr);
|
||||
}
|
||||
@@ -90,7 +95,7 @@ private:
|
||||
#elif __linux__
|
||||
pthread_t handle_;
|
||||
#endif
|
||||
void* returnValuePtr = nullptr;
|
||||
std::shared_ptr<void> returnValuePtr;
|
||||
bool detached = false;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user