3 #include <condition_variable> 5 #include <eris/types.hpp> 9 #include <eris/noncopyable.hpp> 10 #include "creativity/state/State.hpp" 12 namespace creativity {
struct CreativitySettings; }
38 virtual size_t size() = 0;
60 void flush(
bool flush_buffers =
true);
69 bool flush_for(
long milliseconds,
bool flush_buffers =
true);
75 virtual void enqueue(std::shared_ptr<const State> &&s);
86 virtual std::shared_ptr<const State>
load(eris::eris_time_t t) = 0;
113 std::queue<std::shared_ptr<const State>> queue_;
117 unsigned queue_pending_ = 0;
122 bool flush_pending_ =
false;
128 mutable std::mutex queue_mutex_;
133 std::condition_variable queue_cv_;
137 std::condition_variable queue_finished_cv_;
149 bool thread_quit_ =
false;
virtual void writeSettings()=0
Writes the settings in settings_ to the storage medium (if appropriate).
Primary namespace for all Creativity library code.
Definition: config.hpp:4
virtual void thread_insert(std::shared_ptr< const State > &&s)
Called from the queue thread to write the given State to the underlying storage.
StorageBackend(CreativitySettings &settings)
Constructor: takes a CreativitySettings reference.
Definition: StorageBackend.hpp:31
bool empty()
Returns true if the container is empty; exactly equivalent to size() == 0
virtual void enqueue(std::shared_ptr< const State > &&s)
Adds a state to this storage container.
void flush(bool flush_buffers=true)
Flushes changes.
virtual void reserve(size_t T)
Optional method that subclasses can override if knowing the number of states that will be stored in a...
virtual size_t pending() const
Returns the number of states still pending in the queue.
virtual size_t size()=0
Returns the number of states stored in the storage object, not including queued but not-yet-added sta...
CreativitySettings & settings_
CreativitySettings reference.
Definition: StorageBackend.hpp:106
bool flush_for(long milliseconds, bool flush_buffers=true)
Attempts to flush changes, waiting at most the given number of milliseconds for the flush to complete...
virtual ~StorageBackend()
Virtual destructor that tells the thread (if created) to quit and waits for it.
Simulation parameters that are used to configure the simulation when calling setup().
Definition: CreativitySettings.hpp:10
Base class for state storage which accesses State values.
Definition: StorageBackend.hpp:26
virtual std::shared_ptr< const State > load(eris::eris_time_t t)=0
Gets the requested state from the backend.
virtual void storage_flush()
Flush any buffered data to the underlying storage system.