Example use of sharded_parameter.
#include <seastar/core/sharded.hh>
#include <seastar/core/app-template.hh>
#include <seastar/core/thread.hh>
#include <cassert>
class service_one {
int _capacity = 7;
public:
int get_capacity() const { return _capacity; }
};
class service_two {
int _resource_allocation;
public:
service_two(service_one& s1, int resource_allocation) : _resource_allocation(resource_allocation) {}
int get_resource_allocation() const { return _resource_allocation; }
};
int main(int ac, char** av) {
seastar::app_template app;
return app.run(ac, av, [&] {
auto calculate_half_capacity = [] (service_one& s1) {
return s1.get_capacity() / 2;
};
).get();
assert(s2.get_resource_allocation() == 3);
}).get();
});
});
}
Definition: closeable.hh:118
Helper to pass a parameter to a sharded<> object that depends on the shard. It is evaluated on the sh...
Definition: sharded.hh:550
Definition: sharded.hh:182
future invoke_on_all(smp_submit_to_options options, std::function< future<>(Service &)> func) noexcept
Definition: sharded.hh:755
future start(Args &&... args) noexcept
Definition: sharded.hh:624
futurize_t< std::invoke_result_t< Func, Args... > > async(thread_attributes attr, Func &&func, Args &&... args) noexcept
Definition: thread.hh:245
reference_wrapper< T > ref(T &object) noexcept
Wraps reference in a reference_wrapper.
Definition: reference_wrapper.hh:62