Skip to content

Commit b2f00ea

Browse files
committed
Format all files
1 parent 3360368 commit b2f00ea

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+4093
-3934
lines changed

trantor/net/EventLoop.cc

Lines changed: 196 additions & 188 deletions
Large diffs are not rendered by default.

trantor/net/EventLoop.h

Lines changed: 70 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -25,82 +25,83 @@
2525
#include <functional>
2626
namespace trantor
2727
{
28-
class Poller;
29-
class TimerQueue;
30-
class Channel;
31-
typedef std::vector<Channel*> ChannelList;
32-
typedef std::function<void ()> Func;
33-
typedef uint64_t TimerId;
34-
class EventLoop:NonCopyable
28+
class Poller;
29+
class TimerQueue;
30+
class Channel;
31+
typedef std::vector<Channel *> ChannelList;
32+
typedef std::function<void()> Func;
33+
typedef uint64_t TimerId;
34+
class EventLoop : NonCopyable
35+
{
36+
public:
37+
EventLoop();
38+
~EventLoop();
39+
void loop();
40+
void quit();
41+
void assertInLoopThread()
3542
{
36-
public:
37-
EventLoop();
38-
~EventLoop();
39-
void loop();
40-
void quit();
41-
void assertInLoopThread()
43+
if (!isInLoopThread())
4244
{
43-
if(!isInLoopThread())
44-
{
45-
abortNotInLoopThread();
46-
}
47-
};
48-
void resetTimerQueue();
49-
bool isInLoopThread() const { return threadId_ == std::this_thread::get_id();};
50-
static EventLoop* getEventLoopOfCurrentThread();
51-
void updateChannel(Channel *chl);
52-
void removeChannel(Channel *chl);
53-
void runInLoop(const Func &f);
54-
void runInLoop(Func &&f);
55-
void queueInLoop(const Func &f);
56-
void queueInLoop(Func &&f);
57-
void wakeup();
58-
void wakeupRead();
59-
///
60-
/// Runs callback at 'time'.
61-
/// Safe to call from other threads.
62-
///
63-
TimerId runAt(const Date& time, const Func& cb);
64-
TimerId runAt(const Date& time, Func&& cb);
65-
///
66-
/// Runs callback after @c delay seconds.
67-
/// Safe to call from other threads.
68-
///
69-
TimerId runAfter(double delay, const Func& cb);
70-
TimerId runAfter(double delay, Func&& cb);
71-
///
72-
/// Runs callback every @c interval seconds.
73-
/// Safe to call from other threads.
74-
///
75-
TimerId runEvery(double interval, const Func& cb);
76-
TimerId runEvery(double interval, Func&& cb);
77-
//int getAioEventFd();
78-
//io_context_t getAioContext() {return ctx_;};
79-
void invalidateTimer(TimerId id);
80-
private:
81-
void abortNotInLoopThread();
82-
bool looping_;
83-
const std::thread::id threadId_;
84-
bool quit_;
85-
std::unique_ptr<Poller> poller_;
45+
abortNotInLoopThread();
46+
}
47+
};
48+
void resetTimerQueue();
49+
bool isInLoopThread() const { return threadId_ == std::this_thread::get_id(); };
50+
static EventLoop *getEventLoopOfCurrentThread();
51+
void updateChannel(Channel *chl);
52+
void removeChannel(Channel *chl);
53+
void runInLoop(const Func &f);
54+
void runInLoop(Func &&f);
55+
void queueInLoop(const Func &f);
56+
void queueInLoop(Func &&f);
57+
void wakeup();
58+
void wakeupRead();
59+
///
60+
/// Runs callback at 'time'.
61+
/// Safe to call from other threads.
62+
///
63+
TimerId runAt(const Date &time, const Func &cb);
64+
TimerId runAt(const Date &time, Func &&cb);
65+
///
66+
/// Runs callback after @c delay seconds.
67+
/// Safe to call from other threads.
68+
///
69+
TimerId runAfter(double delay, const Func &cb);
70+
TimerId runAfter(double delay, Func &&cb);
71+
///
72+
/// Runs callback every @c interval seconds.
73+
/// Safe to call from other threads.
74+
///
75+
TimerId runEvery(double interval, const Func &cb);
76+
TimerId runEvery(double interval, Func &&cb);
77+
//int getAioEventFd();
78+
//io_context_t getAioContext() {return ctx_;};
79+
void invalidateTimer(TimerId id);
8680

87-
ChannelList activeChannels_;
88-
Channel *currentActiveChannel_;
81+
private:
82+
void abortNotInLoopThread();
83+
bool looping_;
84+
const std::thread::id threadId_;
85+
bool quit_;
86+
std::unique_ptr<Poller> poller_;
8987

90-
bool eventHandling_;
88+
ChannelList activeChannels_;
89+
Channel *currentActiveChannel_;
9190

92-
std::mutex funcsMutex_;
91+
bool eventHandling_;
9392

94-
std::vector<Func> funcs_;
95-
std::unique_ptr<TimerQueue> timerQueue_;
96-
bool callingFuncs_=false;
93+
std::mutex funcsMutex_;
94+
95+
std::vector<Func> funcs_;
96+
std::unique_ptr<TimerQueue> timerQueue_;
97+
bool callingFuncs_ = false;
9798
#ifdef __linux__
98-
int wakeupFd_;
99+
int wakeupFd_;
99100
#else
100-
int wakeupFd_[2];
101+
int wakeupFd_[2];
101102
#endif
102-
std::unique_ptr<Channel> wakeupChannelPtr_;
103+
std::unique_ptr<Channel> wakeupChannelPtr_;
103104

104-
void doRunInLoopFuncs();
105-
};
106-
}
105+
void doRunInLoopFuncs();
106+
};
107+
} // namespace trantor

trantor/net/EventLoopThread.cc

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
#include <trantor/utils/SerialTaskQueue.h>
44

55
using namespace trantor;
6-
EventLoopThread::EventLoopThread():
7-
loop_(NULL),
8-
loopQueue_("EventLoopThread")
6+
EventLoopThread::EventLoopThread()
7+
: loop_(NULL),
8+
loopQueue_("EventLoopThread")
99
{
10-
1110
}
12-
EventLoopThread::~EventLoopThread() {
13-
if(loop_)// not in 100% multiple thread security
11+
EventLoopThread::~EventLoopThread()
12+
{
13+
if (loop_) // not in 100% multiple thread security
1414
{
1515
loop_->quit();
1616
}
@@ -19,23 +19,26 @@ EventLoopThread::~EventLoopThread() {
1919
// if(loop_)
2020
// loop_->quit();
2121
//}
22-
void EventLoopThread::wait() {
22+
void EventLoopThread::wait()
23+
{
2324
loopQueue_.waitAllTasksFinished();
2425
}
25-
void EventLoopThread::loopFuncs() {
26+
void EventLoopThread::loopFuncs()
27+
{
2628
EventLoop loop;
2729
{
2830
std::lock_guard<std::mutex> guard(mutex_);
29-
loop_=&loop;
31+
loop_ = &loop;
3032
cond_.notify_one();
3133
}
3234
loop.loop();
33-
loop_=NULL;
35+
loop_ = NULL;
3436
}
35-
void EventLoopThread::run() {
36-
loopQueue_.runTaskInQueue(std::bind(&EventLoopThread::loopFuncs,this));
37+
void EventLoopThread::run()
38+
{
39+
loopQueue_.runTaskInQueue(std::bind(&EventLoopThread::loopFuncs, this));
3740
std::unique_lock<std::mutex> lock(mutex_);
38-
while(loop_==NULL)
41+
while (loop_ == NULL)
3942
{
4043
cond_.wait(lock);
4144
}

trantor/net/EventLoopThread.h

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,21 @@
66
#include <mutex>
77
namespace trantor
88
{
9-
class EventLoopThread:NonCopyable
10-
{
11-
public:
12-
EventLoopThread();
13-
~EventLoopThread();
14-
void run();
15-
//void stop();
16-
void wait();
17-
EventLoop * getLoop(){return loop_;}
9+
class EventLoopThread : NonCopyable
10+
{
11+
public:
12+
EventLoopThread();
13+
~EventLoopThread();
14+
void run();
15+
//void stop();
16+
void wait();
17+
EventLoop *getLoop() { return loop_; }
1818

19-
private:
20-
EventLoop *loop_;
21-
SerialTaskQueue loopQueue_;
22-
void loopFuncs();
23-
std::condition_variable cond_;
24-
std::mutex mutex_;
25-
};
26-
}
19+
private:
20+
EventLoop *loop_;
21+
SerialTaskQueue loopQueue_;
22+
void loopFuncs();
23+
std::condition_variable cond_;
24+
std::mutex mutex_;
25+
};
26+
} // namespace trantor

trantor/net/EventLoopThreadPool.cc

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
#include <trantor/net/EventLoopThreadPool.h>
22
using namespace trantor;
3-
EventLoopThreadPool::EventLoopThreadPool(size_t threadNum):
4-
loopThreadVector_(threadNum),
5-
loopIndex_(0)
3+
EventLoopThreadPool::EventLoopThreadPool(size_t threadNum)
4+
: loopThreadVector_(threadNum),
5+
loopIndex_(0)
66
{
7-
87
}
9-
void EventLoopThreadPool::start(){
10-
for(unsigned int i=0;i<loopThreadVector_.size();i++)
8+
void EventLoopThreadPool::start()
9+
{
10+
for (unsigned int i = 0; i < loopThreadVector_.size(); i++)
1111
{
1212
loopThreadVector_[i].run();
1313
}
@@ -18,19 +18,21 @@ void EventLoopThreadPool::start(){
1818
// loopThreadVector_[i].stop();
1919
// }
2020
//}
21-
void EventLoopThreadPool::wait() {
22-
for(unsigned int i=0;i<loopThreadVector_.size();i++)
21+
void EventLoopThreadPool::wait()
22+
{
23+
for (unsigned int i = 0; i < loopThreadVector_.size(); i++)
2324
{
2425
loopThreadVector_[i].wait();
2526
}
2627
}
27-
EventLoop *EventLoopThreadPool::getNextLoop(){
28-
if(loopThreadVector_.size()>0)
28+
EventLoop *EventLoopThreadPool::getNextLoop()
29+
{
30+
if (loopThreadVector_.size() > 0)
2931
{
30-
EventLoop *loop=loopThreadVector_[loopIndex_].getLoop();
32+
EventLoop *loop = loopThreadVector_[loopIndex_].getLoop();
3133
loopIndex_++;
32-
if(loopIndex_>=loopThreadVector_.size())
33-
loopIndex_=0;
34+
if (loopIndex_ >= loopThreadVector_.size())
35+
loopIndex_ = 0;
3436
return loop;
3537
}
3638
return NULL;

trantor/net/EventLoopThreadPool.h

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,19 @@
44
#include <vector>
55
namespace trantor
66
{
7-
class EventLoopThreadPool:NonCopyable
8-
{
9-
public:
10-
EventLoopThreadPool()= delete;
11-
EventLoopThreadPool(size_t threadNum);
12-
void start();
13-
//void stop();
14-
void wait();
15-
size_t getLoopNum(){return loopThreadVector_.size();}
16-
EventLoop *getNextLoop();
17-
private:
18-
std::vector<EventLoopThread> loopThreadVector_;
19-
size_t loopIndex_;
20-
};
21-
}
7+
class EventLoopThreadPool : NonCopyable
8+
{
9+
public:
10+
EventLoopThreadPool() = delete;
11+
EventLoopThreadPool(size_t threadNum);
12+
void start();
13+
//void stop();
14+
void wait();
15+
size_t getLoopNum() { return loopThreadVector_.size(); }
16+
EventLoop *getNextLoop();
17+
18+
private:
19+
std::vector<EventLoopThread> loopThreadVector_;
20+
size_t loopIndex_;
21+
};
22+
} // namespace trantor

0 commit comments

Comments
 (0)