Skip to content

Add a non-blocking exec method to schedulers #127

Closed
@daniele77

Description

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(); }
...
};

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions