diff --git a/etk/log.cpp b/etk/log.cpp index e4dce5f..409fc34 100644 --- a/etk/log.cpp +++ b/etk/log.cpp @@ -224,62 +224,52 @@ static std::map& getThreadList() { } std::string etk::log::getThreadName() { - #if __CPP_VERSION__ >= 2011 - std::map& list = getThreadList(); - uint32_t threadID = getThreadID(); - std::string out; - static std11::mutex g_lock; - g_lock.lock(); - auto it = list.find(threadID); - if (it != list.end()) { - out = it->second; - } - g_lock.unlock(); - return out; - #else - return ""; - #endif + std::map& list = getThreadList(); + uint32_t threadID = getThreadID(); + std::string out; + static std11::mutex g_lock; + g_lock.lock(); + std::map::iterator it = list.find(threadID); + if (it != list.end()) { + out = it->second; + } + g_lock.unlock(); + return out; } void etk::log::setThreadName(const std::string& _name) { - #if __CPP_VERSION__ >= 2011 - std::map& list = getThreadList(); - uint32_t threadID = getThreadID(); - static std11::mutex g_lock; - g_lock.lock(); - auto it = list.find(threadID); - if (it == list.end()) { - list.insert(std::pair(threadID,_name)); - } else { - it->second = _name; - } - g_lock.unlock(); - #endif + std::map& list = getThreadList(); + uint32_t threadID = getThreadID(); + static std11::mutex g_lock; + g_lock.lock(); + std::map::iterator it = list.find(threadID); + if (it == list.end()) { + list.insert(std::pair(threadID,_name)); + } else { + it->second = _name; + } + g_lock.unlock(); } uint32_t etk::log::getThreadID() { - #if __CPP_VERSION__ >= 2011 - uint32_t out = 0; - std::thread::id this_id = std::this_thread::get_id(); - uint64_t iddd = std::hash()(this_id); - static std11::mutex g_lock; - g_lock.lock(); - static std::map g_list; - auto it = g_list.find(iddd); - if (it == g_list.end()) { - // attribute new ID : - static uint32_t tmpId = 0; - g_list.insert(std::pair(iddd,tmpId)); - out = tmpId; - tmpId++; - } else { - out = it->second; - } - g_lock.unlock(); - return out; - #else - return 0; - #endif + uint32_t out = 0; + std11::thread::id this_id = std11::this_thread::get_id(); + uint64_t iddd = std11::hash()(this_id); + static std11::mutex g_lock; + g_lock.lock(); + static std::map g_list; + std::map::iterator it = g_list.find(iddd); + if (it == g_list.end()) { + // attribute new ID : + static uint32_t tmpId = 0; + g_list.insert(std::pair(iddd,tmpId)); + out = tmpId; + tmpId++; + } else { + out = it->second; + } + g_lock.unlock(); + return out; } static void getDisplayTime(char* data) { @@ -403,32 +393,30 @@ void etk::log::logChar(int32_t _id, int32_t _level, int32_t _ligne, const char* *pointer++ = ' '; *pointer = '\0'; } - #if __CPP_VERSION__ >= 2011 - if(getThreadId() == true) { - // display thread ID - uint32_t iddd = etk::log::getThreadID(); - sprintf(pointer, "%3d", iddd); - pointer = handle+strlen(handle); - *pointer++ = ' '; - *pointer++ = '|'; + if(getThreadId() == true) { + // display thread ID + uint32_t iddd = etk::log::getThreadID(); + sprintf(pointer, "%3d", iddd); + pointer = handle+strlen(handle); + *pointer++ = ' '; + *pointer++ = '|'; + *pointer++ = ' '; + *pointer = '\0'; + } + if(getThreadNameEnable() == true) { + // display thread ID + std::string name = etk::log::getThreadName(); + int32_t len = strlen(handle); + snprintf(pointer, 20, "%s", name.c_str()); + pointer = handle+strlen(handle); + while (strlen(handle) - len < 20) { *pointer++ = ' '; *pointer = '\0'; } - if(getThreadNameEnable() == true) { - // display thread ID - std::string name = etk::log::getThreadName(); - int32_t len = strlen(handle); - snprintf(pointer, 20, "%s", name.c_str()); - pointer = handle+strlen(handle); - while (strlen(handle) - len < 20) { - *pointer++ = ' '; - *pointer = '\0'; - } - *pointer++ = '|'; - *pointer++ = ' '; - *pointer = '\0'; - } - #endif + *pointer++ = '|'; + *pointer++ = ' '; + *pointer = '\0'; + } if(getLine() == true) { if (_ligne >= 0) { sprintf(pointer, "(l=%5d)", _ligne); diff --git a/etk/stdTools.cpp b/etk/stdTools.cpp index bd902ca..60101ea 100644 --- a/etk/stdTools.cpp +++ b/etk/stdTools.cpp @@ -1392,7 +1392,7 @@ namespace std { int32_t hour = (totalSecond/3600)%24; int32_t day = (totalSecond/(24*3600))%365; int32_t year = totalSecond/(24*3600*365); - _os << year << "y " << day << "d " << hour << "h" << minute << ":"<< second << "s " << millisecond << "ms " << microsecond << "µs " << nanosecond << "ns"; + _os << year << "y " << day << "d " << hour << "h" << minute << ":"<< second << "s " << millisecond << "ms " << microsecond << "µs " << nanosecond << "ns"; return _os; } } \ No newline at end of file