Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a non-blocking exec method to schedulers #127

Closed
daniele77 opened this issue Oct 1, 2021 · 0 comments
Closed

Add a non-blocking exec method to schedulers #127

daniele77 opened this issue Oct 1, 2021 · 0 comments
Assignees

Comments

@daniele77
Copy link
Owner

Add a new non-blocking function to schedulers as explained in discussion #126 . E.g.;

class LoopScheduler
{
...
bool ExecOne()
{
    std::function<void()> task;
    {
      std::unique_lock<std::mutex> lck(mtx);
      cv.wait(lck, [this](){ return !running || !tasks.empty(); });
      if (!running)
          return false;
      task = tasks.front();
      tasks.pop();
  }

  if (task)
      task();

  return true;
}

bool PollOne()
{
    std::function<void()> task;
    {
        std::unique_lock<std::mutex> lck(mtx);
        if (!running || tasks.empty())
            return false;
        task = tasks.front();
        tasks.pop();
    }

    if (task)
        task();

    return true;
}
...
};

class AsioScheduler
{        
 ...
void ExecOne() { context->run_one(); }
void PollOne() { context->poll_one(); }
...
};
@daniele77 daniele77 self-assigned this Oct 4, 2021
hanyukang pushed a commit to hanyukang/cli that referenced this issue Oct 6, 2021
Add WorkGuard for boost and asio libs.

The Stop() method in GenericAsioScheduler class should be calling workguard.reset() for releasing the corresponding work in the io_context object.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant