Skip to content

Commit 00fca04

Browse files
authored
Add index() interface to the EventLoop class (#55)
1 parent e95f82d commit 00fca04

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

trantor/net/EventLoop.cc

Lines changed: 2 additions & 2 deletions
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 = 0;
54+
__thread EventLoop *t_loopInThisThread = nullptr;
5555

5656
EventLoop::EventLoop()
5757
: _looping(false),
@@ -98,7 +98,7 @@ void EventLoop::resetAfterFork()
9898
EventLoop::~EventLoop()
9999
{
100100
assert(!_looping);
101-
t_loopInThisThread = NULL;
101+
t_loopInThisThread = nullptr;
102102
#ifdef __linux__
103103
close(_wakeupFd);
104104
#else

trantor/net/EventLoop.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,14 @@ class EventLoop : NonCopyable
7171
void queueInLoop(Func &&f);
7272
void wakeup();
7373
void wakeupRead();
74+
size_t index()
75+
{
76+
return _index;
77+
}
78+
void setIndex(size_t index)
79+
{
80+
_index = index;
81+
}
7482
// template <typename T>
7583
// const std::shared_ptr<ObjectPool<T>> &getObjectPool()
7684
// {
@@ -169,6 +177,7 @@ class EventLoop : NonCopyable
169177
std::unique_ptr<Channel> _wakeupChannelPtr;
170178

171179
void doRunInLoopFuncs();
180+
size_t _index = -1;
172181
};
173182

174183
} // namespace trantor

0 commit comments

Comments
 (0)