2023-10-24 20:31:03 +03:00

46 lines
849 B
C++

//
// Created by erki on 24/10/23.
//
#pragma once
#include <tuple>
#include <utility_function.hpp>
#include <utility_ringbuffer.hpp>
#include "cpptick/argstore.hpp"
namespace cpptick
{
struct Scheduler
{
using StoredCall = std::pair<Utility::IFunction<void (ArgStorage&)>*, ArgStorage>;
Utility::Ringbuffer<StoredCall, 12> stored_calls;
void tick()
{
if (!stored_calls.empty())
{
auto* f = stored_calls.begin()->first;
auto& args = stored_calls.begin()->second;
(*f)(args);
stored_calls.pop_front();
}
}
ArgStorage& storeCall(Utility::IFunction<void (ArgStorage&)>* call)
{
// @todo: handle overflow...
// still constructs double.
stored_calls.emplace_back(call, ArgStorage{});
auto& storage = stored_calls.back().second;
storage.reset();
return storage;
}
};
}