mirror of
https://github.com/davidgiven/fluxengine.git
synced 2025-10-31 11:17:01 -07:00
Add functionality for clearing the cache between runs.
This commit is contained in:
@@ -8,6 +8,7 @@ LIBFLUXENGINE_SRCS = \
|
|||||||
lib/decoders/fluxmapreader.cc \
|
lib/decoders/fluxmapreader.cc \
|
||||||
lib/decoders/fmmfm.cc \
|
lib/decoders/fmmfm.cc \
|
||||||
lib/encoders/encoders.cc \
|
lib/encoders/encoders.cc \
|
||||||
|
lib/environment.cc \
|
||||||
lib/flags.cc \
|
lib/flags.cc \
|
||||||
lib/fluxmap.cc \
|
lib/fluxmap.cc \
|
||||||
lib/fluxsink/a2rfluxsink.cc \
|
lib/fluxsink/a2rfluxsink.cc \
|
||||||
|
|||||||
17
lib/environment.cc
Normal file
17
lib/environment.cc
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
#include "lib/globals.h"
|
||||||
|
#include "lib/environment.h"
|
||||||
|
|
||||||
|
static std::unique_ptr<std::set<LocalBase*>> variables;
|
||||||
|
|
||||||
|
void Environment::reset()
|
||||||
|
{
|
||||||
|
for (LocalBase* var : *variables)
|
||||||
|
var->reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Environment::addVariable(LocalBase* local)
|
||||||
|
{
|
||||||
|
if (!variables)
|
||||||
|
variables = std::make_unique<std::set<LocalBase*>>();
|
||||||
|
variables->insert(local);
|
||||||
|
}
|
||||||
44
lib/environment.h
Normal file
44
lib/environment.h
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
#ifndef ENVIRONMENT_H
|
||||||
|
#define ENVIRONMENT_H
|
||||||
|
|
||||||
|
class LocalBase;
|
||||||
|
|
||||||
|
class Environment
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static void reset();
|
||||||
|
static void addVariable(LocalBase* local);
|
||||||
|
};
|
||||||
|
|
||||||
|
class LocalBase
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual void reset() = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
class Local : LocalBase
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Local()
|
||||||
|
{
|
||||||
|
Environment::addVariable(this);
|
||||||
|
}
|
||||||
|
void reset() override
|
||||||
|
{
|
||||||
|
_value.clear();
|
||||||
|
}
|
||||||
|
T& operator*()
|
||||||
|
{
|
||||||
|
return _value;
|
||||||
|
}
|
||||||
|
T& operator->()
|
||||||
|
{
|
||||||
|
return _value;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
T _value;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -1,9 +1,11 @@
|
|||||||
#include "lib/globals.h"
|
#include "lib/globals.h"
|
||||||
#include "lib/layout.h"
|
#include "lib/layout.h"
|
||||||
#include "lib/proto.h"
|
#include "lib/proto.h"
|
||||||
|
#include "lib/environment.h"
|
||||||
#include <fmt/format.h>
|
#include <fmt/format.h>
|
||||||
|
|
||||||
static std::map<std::pair<int, int>, std::unique_ptr<Layout>> layoutCache;
|
static Local<std::map<std::pair<int, int>, std::unique_ptr<Layout>>>
|
||||||
|
layoutCache;
|
||||||
|
|
||||||
std::vector<std::pair<int, int>> Layout::getTrackOrdering(
|
std::vector<std::pair<int, int>> Layout::getTrackOrdering(
|
||||||
unsigned guessedTracks, unsigned guessedSides)
|
unsigned guessedTracks, unsigned guessedSides)
|
||||||
@@ -66,7 +68,7 @@ static void expandSectors(const LayoutProto::SectorsProto& sectorsProto,
|
|||||||
|
|
||||||
const Layout& Layout::getLayoutOfTrack(unsigned track, unsigned side)
|
const Layout& Layout::getLayoutOfTrack(unsigned track, unsigned side)
|
||||||
{
|
{
|
||||||
auto& layout = layoutCache[std::make_pair(track, side)];
|
auto& layout = (*layoutCache)[std::make_pair(track, side)];
|
||||||
if (!layout)
|
if (!layout)
|
||||||
{
|
{
|
||||||
layout.reset(new Layout());
|
layout.reset(new Layout());
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "lib/config.pb.h"
|
#include "lib/config.pb.h"
|
||||||
#include "proto.h"
|
#include "proto.h"
|
||||||
|
#include "environment.h"
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
|
||||||
enum ReadResult
|
enum ReadResult
|
||||||
@@ -228,6 +229,7 @@ void writeTracks(FluxSink& fluxSink,
|
|||||||
std::function<bool(const Location& location)> verifier,
|
std::function<bool(const Location& location)> verifier,
|
||||||
const std::set<Location>& locations)
|
const std::set<Location>& locations)
|
||||||
{
|
{
|
||||||
|
Environment::reset();
|
||||||
Logger() << BeginOperationLogMessage{"Encoding and writing to disk"};
|
Logger() << BeginOperationLogMessage{"Encoding and writing to disk"};
|
||||||
|
|
||||||
int index = 0;
|
int index = 0;
|
||||||
@@ -416,6 +418,7 @@ void writeRawDiskCommand(FluxSource& fluxSource, FluxSink& fluxSink)
|
|||||||
std::shared_ptr<TrackFlux> readAndDecodeTrack(
|
std::shared_ptr<TrackFlux> readAndDecodeTrack(
|
||||||
FluxSource& fluxSource, AbstractDecoder& decoder, const Location& location)
|
FluxSource& fluxSource, AbstractDecoder& decoder, const Location& location)
|
||||||
{
|
{
|
||||||
|
Environment::reset();
|
||||||
auto trackFlux = std::make_shared<TrackFlux>();
|
auto trackFlux = std::make_shared<TrackFlux>();
|
||||||
trackFlux->location = location;
|
trackFlux->location = location;
|
||||||
|
|
||||||
@@ -450,6 +453,7 @@ std::shared_ptr<TrackFlux> readAndDecodeTrack(
|
|||||||
std::shared_ptr<const DiskFlux> readDiskCommand(
|
std::shared_ptr<const DiskFlux> readDiskCommand(
|
||||||
FluxSource& fluxSource, AbstractDecoder& decoder)
|
FluxSource& fluxSource, AbstractDecoder& decoder)
|
||||||
{
|
{
|
||||||
|
Environment::reset();
|
||||||
std::unique_ptr<FluxSink> outputFluxSink;
|
std::unique_ptr<FluxSink> outputFluxSink;
|
||||||
if (config.decoder().has_copy_flux_to())
|
if (config.decoder().has_copy_flux_to())
|
||||||
outputFluxSink = FluxSink::create(config.decoder().copy_flux_to());
|
outputFluxSink = FluxSink::create(config.decoder().copy_flux_to());
|
||||||
@@ -565,6 +569,7 @@ void rawReadDiskCommand(FluxSource& fluxsource, FluxSink& fluxsink)
|
|||||||
{
|
{
|
||||||
Logger() << BeginOperationLogMessage{"Performing raw read of disk"};
|
Logger() << BeginOperationLogMessage{"Performing raw read of disk"};
|
||||||
|
|
||||||
|
Environment::reset();
|
||||||
auto tracks = iterate(config.tracks());
|
auto tracks = iterate(config.tracks());
|
||||||
auto heads = iterate(config.heads());
|
auto heads = iterate(config.heads());
|
||||||
unsigned locations = tracks.size() * heads.size();
|
unsigned locations = tracks.size() * heads.size();
|
||||||
|
|||||||
Reference in New Issue
Block a user