diff options
author | Siddarth Suresh <155843085+SiddarthSuresh98@users.noreply.github.com> | 2025-04-16 12:41:34 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-04-16 12:41:34 -0400 |
commit | 43e660152ebf1d8c8aa46f5478d4d26885d4a12c (patch) | |
tree | 41ab4e108784f6c180ad23fcc3bd3bf9440a9a2b /src/storage.cc | |
parent | be2bc108dc112ae7e21d4a77f7bcbfac88d6fcd4 (diff) | |
parent | 71f69927931e007d0bac13b9268b6a697b45c70a (diff) |
Merge pull request #2 from bdunahu/bdunahu
[WIP] Memory Rewrite
Diffstat (limited to 'src/storage.cc')
-rw-r--r-- | src/storage.cc | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/src/storage.cc b/src/storage.cc index 4ad916b..ee2e7e7 100644 --- a/src/storage.cc +++ b/src/storage.cc @@ -1,8 +1,10 @@ #include "storage.h" #include "definitions.h" #include <algorithm> +#include <stdexcept> -Storage::Storage(int delay) { +Storage::Storage(int delay) +{ this->data = new std::vector<std::array<signed int, LINE_SIZE>>; this->delay = delay; this->lower = nullptr; @@ -18,3 +20,32 @@ Storage::view(int base, int lines) const std::copy(this->data->begin() + base, this->data->begin() + base + lines, ret.begin()); return ret; } + +int +Storage::preprocess(void *id) +{ + if (id == nullptr) + throw std::invalid_argument("Accessor cannot be nullptr."); + + if (this->current_request == nullptr) + this->current_request = id; + + return this->current_request == id; +} + +int +Storage::is_data_ready() +{ + int r; + + r = 0; + if (this->wait_time == 0) { + this->current_request = nullptr; + this->wait_time = delay; + r = 1; + } else { + --this->wait_time; + } + + return r; +} |