Skip to content

Commit

Permalink
[src] Improve EventManager and ReactorManager
Browse files Browse the repository at this point in the history
  • Loading branch information
Sigma711 committed Aug 11, 2023
1 parent 7148853 commit 4fc9587
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 12 deletions.
6 changes: 3 additions & 3 deletions src/event_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -205,12 +205,12 @@ void EventManager::WakeUp() {
#endif
}

void EventManager::Quit() { should_quit_ = true; }
void EventManager::Quit() { should_quit_.store(true); }

void EventManager::Start() {
should_quit_ = false;
should_quit_.store(false);
LOG_DEBUG("The event loop in thread(%lu) is starting.", ::pthread_self());
while (!should_quit_) {
while (!should_quit_.load()) {
auto return_time =
poller_.Poll(timer_.GetMinTimeDuration(),
&active_events_); // Return time is the time point of
Expand Down
3 changes: 2 additions & 1 deletion src/event_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include <stdint.h>

#include <atomic>
#include <functional>
#include <memory>
#include <mutex>
Expand Down Expand Up @@ -125,7 +126,7 @@ class EventManager : NonCopyableMovable {
mutable MutexLock connection_map_mutex_lock_;

// The flag for deciding whether the event loop should quit
bool should_quit_;
std::atomic_bool should_quit_;

// List for active events returned from the I/O multiplexing waiting each loop
Poller::EventerList active_events_;
Expand Down
7 changes: 0 additions & 7 deletions src/reactor_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ ServerReactorManager::ServerReactorManager(EventManagers* event_managers,
LOG_ERROR("Fail to init the acceptor!!!");
::exit(-1);
}
// TODO: event_managers_[0] = event_managers;
for (size_t i = 0; i < io_thread_amount; ++i) {
// "Initialize" "Reactor"s
(*event_managers_)[i]->SetCreateConnectionCallback(
Expand All @@ -82,12 +81,6 @@ ServerReactorManager::ServerReactorManager(EventManagers* event_managers,
}
balancer_ = std::make_unique<Balancer>(event_managers_, 0);
}
ServerReactorManager::~ServerReactorManager() {
// size_t thread_amount = event_managers_.size();
// for (size_t i = 1; i < thread_amount; ++i) {
// delete event_managers_[i];
// }
}

void ServerReactorManager::Loop() {
size_t io_thread_amount = (*event_managers_).size();
Expand Down
1 change: 0 additions & 1 deletion src/reactor_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ class ServerReactorManager : NonCopyableMovable {
const NetAddress& listen_address,
size_t io_thread_amount = 6,
bool should_reuse_port = false);
~ServerReactorManager();

void SetConnectionCallback(const NormalCallback& cb) {
ConnectionCallback_ = cb;
Expand Down

0 comments on commit 4fc9587

Please sign in to comment.