Skip to content

Commit

Permalink
Avoid repeated EventLoopThread::start
Browse files Browse the repository at this point in the history
  • Loading branch information
ithewei committed Jul 19, 2024
1 parent 8c67e05 commit b350201
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions evpp/EventLoopThread.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class EventLoopThread : public Status {
Functor pre = Functor(),
Functor post = Functor()) {
if (status() >= kStarting && status() < kStopped) return;
if (isRunning()) return;
setStatus(kStarting);

thread_ = std::make_shared<std::thread>(&EventLoopThread::loop_thread, this, pre, post);
Expand Down
4 changes: 3 additions & 1 deletion evpp/TcpServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,9 @@ class TcpServerTmpl : private EventLoopThread, public TcpServerEventLoopTmpl<TSo
// start thread-safe
void start(bool wait_threads_started = true) {
TcpServerEventLoopTmpl<TSocketChannel>::start(wait_threads_started);
EventLoopThread::start(wait_threads_started);
if (!isRunning()) {
EventLoopThread::start(wait_threads_started);
}
}

// stop thread-safe
Expand Down

0 comments on commit b350201

Please sign in to comment.