[io_generator] Simplify the class interface

This commit is contained in:
Ming-Hung Tsai 2020-06-20 00:04:01 +08:00
parent fe754d81a4
commit 084ac4b950
3 changed files with 7 additions and 13 deletions

View File

@ -115,8 +115,7 @@ namespace {
class base_io_generator: public io_generator {
public:
base_io_generator(io_generator_options const &opts);
virtual bool has_next();
virtual void next(base::io &next_io);
virtual bool next(base::io &next_io);
private:
offset_generator::ptr
@ -140,19 +139,17 @@ namespace {
io_size_total_(opts.io_size_) {
}
bool base_io_generator::has_next() {
return io_size_finished_ < io_size_total_;
}
void base_io_generator::next(base::io &next_io) {
bool base_io_generator::next(base::io &next_io) {
if (io_size_finished_ >= io_size_total_)
throw std::runtime_error("");
return false;
next_io.op_ = op_gen_->next_op();
next_io.sector_ = offset_gen_->next_offset();
next_io.size_ = block_size_;
io_size_finished_ += block_size_;
return true;
}
offset_generator::ptr

View File

@ -42,8 +42,7 @@ namespace base {
public:
typedef std::shared_ptr<io_generator> ptr;
virtual bool has_next() = 0;
virtual void next(base::io &next_io) = 0;
virtual bool next(base::io &next_io) = 0;
};
io_generator::ptr

View File

@ -93,10 +93,8 @@ namespace {
io_generator::ptr gen = create_io_generator(opts);
base::io io;
while (gen->has_next()) {
while (gen->next(io)) {
// TODO: support io.size_
gen->next(io);
switch (io.op_) {
case base::REQ_OP_READ:
process_read(td, pool, io.sector_);