둘 다 동시 디버깅을 위해 push
This commit is contained in:
32
impl/Utils/GenerateID.cpp
Normal file
32
impl/Utils/GenerateID.cpp
Normal file
@@ -0,0 +1,32 @@
|
||||
#include "Utils/Snowflake.hpp"
|
||||
|
||||
namespace Chattr {
|
||||
|
||||
Snowflake GenerateID() {
|
||||
static struct _EPOCH {
|
||||
_EPOCH() {
|
||||
EPOCH = std::chrono::system_clock::now();
|
||||
}
|
||||
std::chrono::system_clock::time_point EPOCH;
|
||||
} __EPOCH__;
|
||||
|
||||
static std::mutex snowflakeGenerateMutex_;
|
||||
|
||||
std::lock_guard<std::mutex> lock(snowflakeGenerateMutex_);
|
||||
#ifdef _WIN32
|
||||
DWORD tid = GetCurrentThreadId();
|
||||
#elif __linux__
|
||||
pthread_t tid = pthread_self();
|
||||
#endif
|
||||
static int sequence = 0;
|
||||
Snowflake id = {};
|
||||
|
||||
auto timestamp = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now() - __EPOCH__.EPOCH);
|
||||
id.timestamp = timestamp.count();
|
||||
id.instance = tid;
|
||||
id.sequence = sequence++;
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
};
|
||||
@@ -63,7 +63,7 @@ void* ThreadPool::Worker() {
|
||||
#elif __linux__
|
||||
pthread_t pid = pthread_self();
|
||||
#endif
|
||||
spdlog::debug("ThreadPool Worker : {} up", pid);
|
||||
spdlog::trace("ThreadPool Worker : {} up", pid);
|
||||
while (!terminate_) {
|
||||
std::unique_lock<std::mutex> lock(jobQueueMutex);
|
||||
jobQueueCV_.wait(lock, [this]() { return !this->jobs_.empty() || terminate_; });
|
||||
@@ -78,10 +78,10 @@ void* ThreadPool::Worker() {
|
||||
jobs_.pop();
|
||||
lock.unlock();
|
||||
|
||||
spdlog::debug("ThreadPool Worker : {} Executing a job", pid);
|
||||
spdlog::trace("ThreadPool Worker : {} Executing a job", pid);
|
||||
job();
|
||||
}
|
||||
spdlog::debug("ThreadPool Worker : {} down", pid);
|
||||
spdlog::trace("ThreadPool Worker : {} down", pid);
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user