From 85cc4ab0c5a940aa50ec63d29d1cc1c3745d8aa1 Mon Sep 17 00:00:00 2001 From: HappyTanuki Date: Thu, 24 Apr 2025 20:40:24 +0900 Subject: [PATCH] =?UTF-8?q?=EB=A6=AC=EB=88=85=EC=8A=A4=20=EC=8A=A4?= =?UTF-8?q?=EB=A0=88=EB=93=9C=20=EC=83=9D=EC=84=B1=20&=20=ED=95=B8?= =?UTF-8?q?=EB=93=A4=20=EC=A0=80=EC=9E=A5=EC=9E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/Utils/Chattering.log | 0 include/Utils/Thread.hpp | 24 +++++++++++++++++++----- include/Utils/config.json | 8 ++++++++ 3 files changed, 27 insertions(+), 5 deletions(-) create mode 100644 include/Utils/Chattering.log create mode 100644 include/Utils/config.json diff --git a/include/Utils/Chattering.log b/include/Utils/Chattering.log new file mode 100644 index 0000000..e69de29 diff --git a/include/Utils/Thread.hpp b/include/Utils/Thread.hpp index 8866ea9..e99d4c8 100644 --- a/include/Utils/Thread.hpp +++ b/include/Utils/Thread.hpp @@ -2,7 +2,7 @@ #ifdef _WIN32 #include #elif __linux__ - +#include #else #error "이 플랫폼은 지원되지 않습니다." #endif @@ -10,18 +10,30 @@ namespace Chattr { - class Thread { public: #ifdef _WIN32 - static DWORD WINAPI __thread(LPVOID param) { - std::unique_ptr> func(reinterpret_cast*>(param)); + static DWORD WINAPI thread_func(LPVOID param) { + std::unique_ptr> func(static_cast*>(param)); + (*func)(); + return 0; + } +#elif __linux__ + static void* thread_func(void *param) { + std::unique_ptr> func(static_cast*>(param)); (*func)(); return 0; } #endif template Thread(Callable&& f, Args&&... args); + +private: +#ifdef _WIN32 + HANDLE handle_; +#elif __linux__ + pthread_t handle_; +#endif }; template @@ -31,7 +43,9 @@ Thread::Thread(Callable&& f, Args&&... args) { auto funcPtr = new std::function(boundFunc); #ifdef _WIN32 - CreateThread(nullptr, 0, __thread, funcPtr, 0, nullptr); + handle_ = CreateThread(nullptr, 0, thread_func, funcPtr, 0, nullptr); +#elif __linux__ + pthread_create(&handle_, NULL, thread_func, funcPtr); #endif } diff --git a/include/Utils/config.json b/include/Utils/config.json new file mode 100644 index 0000000..5d7237d --- /dev/null +++ b/include/Utils/config.json @@ -0,0 +1,8 @@ +{ + "IP Version" : 6, + "Listen Port" : 9010, + "LogLevel" : 1, + "LogfileCount" : 5, + "LogfileName" : "Chattering.log", + "LogfileSize" : 4294967295 +} \ No newline at end of file