File multiprocess_time_series.hpp¶
-
namespace time_series
Functions
-
void clear_memory(std::string segment_id)¶
Wipe out the corresponding shared memory.
Useful if no instances of MultiprocessTimeSeries cleared the memory on destruction. Reusing the segment id of a non-wiped shared memory may result in the newly created instance to hang.
-
template<typename T = int>
class MultiprocessTimeSeries : public internal::TimeSeriesBase<internal::MultiProcesses, int> - #include <multiprocess_time_series.hpp>
Multiprocess Time Series.
Several instances hosted by different processes, if pointing to the same shared memory segment (as specified by the segment_id), may read/write from the same underlying time series.
Public Functions
-
inline MultiprocessTimeSeries(std::string segment_id, size_t max_length, bool leader = true, Index start_timeindex = 0)
create a new instance pointing to the specified shared memory segment
- Deprecated:
uses the factory functions create_leader or create_follower
- Parameters
segment_id – the id of the segment to point to
max_length – max number of elements in the time series
leader – if true, the shared memory segment will initialize the shared time series, and wiped the related shared memory on destruction. Instantiating a first MultiprocessTimeSeries with leader set to false will result in undefined behavior. When the leader instance is destroyed, other instances are pointing to the shared segment may crash or hang.
-
inline MultiprocessTimeSeries(MultiprocessTimeSeries<T> &&other) noexcept
-
inline std::string get_raw(const Index &timeindex)
similar to the random access operator, but does not deserialized the accessed element.
If the element is of a fundamental type (or an array of), an std::logic_error is thrown.
Public Static Functions
-
static inline size_t get_max_length(const std::string &segment_id)
returns the max length used by a leading MultiprocessTimeSeries of the corresponding segment_id
-
static inline Index get_start_timeindex(const std::string &segment_id)
returns the start index used by a leading MultiprocessTimeSeries of the corresponding segment_id
-
static inline MultiprocessTimeSeries<T> create_leader(const std::string &segment_id, size_t max_length, Index start_timeindex = 0)
returns a leader instance of MultiprocessTimeSeries<T>
- Parameters
segment_id – the id of the segment to point to
max_length – max number of elements in the time series
-
static inline std::shared_ptr<MultiprocessTimeSeries<T>> create_leader_ptr(const std::string &segment_id, size_t max_length, Index start_timeindex = 0)
same as create_leader but returning a shared_ptr.
-
static inline MultiprocessTimeSeries<T> create_follower(const std::string &segment_id)
returns a follower instance of MultiprocessTimeSeries<T>.
An follower instance should be created only if a leader instance has been created first. A std::runtime_error will be thrown otherwise.
- Parameters
segment_id – the id of the segment to point to
-
static inline std::shared_ptr<MultiprocessTimeSeries<T>> create_follower_ptr(const std::string &segment_id)
same as create_follower but returning a shared_ptr.
Protected Static Functions
-
static inline void get_max_length_and_start_index_from_leader(const std::string &segment_id, size_t *max_length, Index *start_timeindex)¶
Load length and start index from leader.
Assumes that a leader time series is already running and providing this information in the shared memory.
- Parameters
segment_id – [in] The id of the segment to point to.
max_length – [out] The max. length of the time series.
start_timeindex – [out]
- Throws
std::runtime_error – If the data cannot be read from the specified shared memory segment.
-
inline MultiprocessTimeSeries(std::string segment_id, size_t max_length, bool leader = true, Index start_timeindex = 0)
-
namespace internal¶
Functions
- static const std::string shm_indexes ("_indexes")
- static const std::string shm_elements ("_elements")
- static const std::string shm_timestamps ("_timestamps")
- static const std::string shm_mutex ("_mutex")
- static const std::string shm_condition_variable ("_condition_variable")
-
void clear_memory(std::string segment_id)¶