Skip to content

Commit

Permalink
fix: OnIdleTask interface (#355)
Browse files Browse the repository at this point in the history
1. Update comments
2. Improve garbage collection of removed tasks.

Signed-off-by: Roman Gershman <[email protected]>
  • Loading branch information
romange authored Dec 28, 2024
1 parent aabaa93 commit 02cac2d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
6 changes: 5 additions & 1 deletion util/fibers/proactor_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,11 @@ bool ProactorBase::RemoveOnIdleTask(uint32_t id) {
return false;

on_idle_arr_[id].task = OnIdleTask{};

while (!on_idle_arr_.back().task) {
on_idle_arr_.pop_back();
if (on_idle_arr_.empty())
break;
}
return true;
}

Expand Down
8 changes: 4 additions & 4 deletions util/fibers/proactor_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,12 @@ class ProactorBase {

/**
* @brief Adds a task that should run when Proactor loop is idle. The task should return
* true if keep it running or false if it finished its job.
*
* Must be called from the proactor thread.
* a freqency level to run - between 0 and kOnIdleMaxLevel, with 0 being most relaxed and
* kOnIdleMaxLevel the most intense. The task will keep running until RemoveOnIdleTask
* is called. Must be called from the proactor thread.
* @tparam Func
* @param f
* @return uint32_t an unique ids denoting this task. Can be used for cancellation.
* @return uint32_t an unique ids denoting this task. Should be passed to RemoveOnIdleTask().
*/
uint32_t AddOnIdleTask(OnIdleTask f);

Expand Down

0 comments on commit 02cac2d

Please sign in to comment.