Skip to content

Commit 99ba85b

Browse files
authored
Use std::numeric_limits (#56)
1 parent 00fca04 commit 99ba85b

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

trantor/net/EventLoop.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ int createEventfd()
5151
}
5252
const int kPollTimeMs = 10000;
5353
#endif
54-
__thread EventLoop *t_loopInThisThread = nullptr;
54+
thread_local EventLoop *t_loopInThisThread = nullptr;
5555

5656
EventLoop::EventLoop()
5757
: _looping(false),

trantor/net/EventLoop.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <queue>
2727
#include <functional>
2828
#include <chrono>
29+
#include <limits>
2930

3031
namespace trantor
3132
{
@@ -177,7 +178,7 @@ class EventLoop : NonCopyable
177178
std::unique_ptr<Channel> _wakeupChannelPtr;
178179

179180
void doRunInLoopFuncs();
180-
size_t _index = -1;
181+
size_t _index = std::numeric_limits<size_t>::max();
181182
};
182183

183184
} // namespace trantor

trantor/utils/Logger.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,14 @@ inline LogStream &operator<<(LogStream &s, const Logger::SourceFile &v)
5555
} // namespace trantor
5656
using namespace trantor;
5757

58-
static __thread uint64_t lastSecond_ = 0;
59-
static __thread char lastTimeString_[32] = {0};
58+
static thread_local uint64_t lastSecond_ = 0;
59+
static thread_local char lastTimeString_[32] = {0};
6060
#ifdef __linux__
61-
static __thread pid_t threadId_ = 0;
61+
static thread_local pid_t threadId_ = 0;
6262
#else
63-
static __thread uint64_t threadId_ = 0;
63+
static thread_local uint64_t threadId_ = 0;
6464
#endif
65-
// static __thread LogStream logStream_;
65+
// static thread_local LogStream logStream_;
6666

6767
void Logger::formatTime()
6868
{

0 commit comments

Comments
 (0)