Skip to content

Commit

Permalink
fix: revised TimerTaskManager and add some comments (OpenAtomFoundati…
Browse files Browse the repository at this point in the history
…on#2776)

* 1 rename DisPatcherThread::timerTaskThread_ to timer_task_thread_
* 2 add comments for TimerTaskManager

---------

Co-authored-by: cheniujh <[email protected]>
  • Loading branch information
cheniujh and cheniujh authored Jul 10, 2024
1 parent a61cfc6 commit b29f8e3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/net/src/dispatch_thread.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ int DispatchThread::StartThread() {
}

// Adding timer tasks and run timertaskThread
timerTaskThread_.AddTimerTask("blrpop_blocking_info_scan", 250, true,
timer_task_thread_.AddTimerTask("blrpop_blocking_info_scan", 250, true,
[this] { this->ScanExpiredBlockedConnsOfBlrpop(); });
timerTaskThread_.set_thread_name("TimerTaskThread");
timerTaskThread_.StartThread();
timer_task_thread_.set_thread_name("TimerTaskThread");
timer_task_thread_.StartThread();
return ServerThread::StartThread();
}

Expand All @@ -88,7 +88,7 @@ int DispatchThread::StopThread() {
worker_thread_[i]->private_data_ = nullptr;
}
}
timerTaskThread_.StopThread();
timer_task_thread_.StopThread();
return ServerThread::StopThread();
}

Expand Down
2 changes: 1 addition & 1 deletion src/net/src/dispatch_thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ class DispatchThread : public ServerThread {
*/
std::shared_mutex block_mtx_;

TimerTaskThread timerTaskThread_;
TimerTaskThread timer_task_thread_;
}; // class DispatchThread

} // namespace net
Expand Down
6 changes: 6 additions & 0 deletions src/net/src/net_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ struct ExecTsWithId {
}
};

/*
* For simplicity, current version of TimerTaskThread has no lock inside and all task should be registered before TimerTaskThread started,
* but if you have the needs of dynamically add/remove timer task after TimerTaskThread started, you can simply add a mutex to protect
* the timer_task_manager_ and also a pipe to wake up the maybe being endless-wait epoll(if all task consumed, epoll will sink into
* endless wait) to implement the feature.
*/
class TimerTaskManager {
public:
TimerTaskManager() = default;
Expand Down

0 comments on commit b29f8e3

Please sign in to comment.