1#ifndef CASACORE_AOCOMMON_LANE_11_H_
2#define CASACORE_AOCOMMON_LANE_11_H_
4#include <condition_variable>
30#define set_lane_debug_name(lane, str) (lane).setDebugName(str)
31#define LANE_REGISTER_DEBUG_INFO registerDebugInfo()
32#define LANE_REGISTER_DEBUG_WRITE_WAIT registerDebugWriteWait()
33#define LANE_REGISTER_DEBUG_READ_WAIT registerDebugReadWait()
34#define LANE_REPORT_DEBUG_INFO reportDebugInfo()
38#define set_lane_debug_name(lane, str)
39#define LANE_REGISTER_DEBUG_INFO
40#define LANE_REGISTER_DEBUG_WRITE_WAIT
41#define LANE_REGISTER_DEBUG_READ_WAIT
42#define LANE_REPORT_DEBUG_INFO
177 std::swap(
_buffer, other._buffer);
181 std::swap(
_status, other._status);
207 std::unique_lock<std::mutex> lock(
_mutex);
235 template <
typename... Args>
237 std::unique_lock<std::mutex> lock(
_mutex);
264 std::unique_lock<std::mutex> lock(
_mutex);
290 std::unique_lock<std::mutex> lock(
_mutex);
310 std::unique_lock<std::mutex> lock(
_mutex);
314 size_t read_size = free_space > n ? n : free_space;
319 destinations += read_size;
327 read_size = free_space > n_left ? n_left : free_space;
342 std::unique_lock<std::mutex> lock(
_mutex);
346 size_t read_size = free_space > n ? n : free_space;
357 read_size = free_space > n_left ? n_left : free_space;
365 std::lock_guard<std::mutex> lock(
_mutex);
375 std::lock_guard<std::mutex> lock(
_mutex);
380 std::lock_guard<std::mutex> lock(
_mutex);
389 std::lock_guard<std::mutex> lock(
_mutex);
397 std::lock_guard<std::mutex> lock(
_mutex);
406 Tp* new_buffer =
new Tp[new_capacity];
419 std::unique_lock<std::mutex> lock(
_mutex);
425#ifdef LANE_DEBUG_MODE
432 void setDebugName(
const std::string& nameStr) { _debugName = nameStr; }
459 template <
typename T>
461 std::unique_lock<std::mutex> lock(
_mutex);
470 elements += write_size;
485 template <
typename T>
526 for (
size_t i = 0; i < nPart; ++i, ++position) {
527 elements[i] = std::move(
_buffer[position]);
532 for (
size_t i = nPart; i < n; ++i, ++position) {
533 elements[i] = std::move(
_buffer[position]);
552#ifdef LANE_DEBUG_MODE
553 void registerDebugInfo() noexcept {
555 _debugMeasureCount++;
557 void registerDebugReadWait() noexcept { ++_debugReadWaitCount; }
558 void registerDebugWriteWait() noexcept { ++_debugWriteWaitCount; }
559 void reportDebugInfo() {
560 if (!_debugName.empty()) {
561 std::stringstream str;
562 str <<
"*** Debug report for the following Lane: ***\n"
563 <<
"\"" << _debugName <<
"\"\n"
565 <<
"Total read/write ops: " << _debugMeasureCount <<
'\n'
566 <<
"Average size of buffer, measured per read/write op.: "
567 <<
round(
double(_debugSummedSize) * 100.0 / _debugMeasureCount) /
570 <<
"Number of wait events during reading: " << _debugReadWaitCount
572 <<
"Number of wait events during writing: " << _debugWriteWaitCount
574 std::cout << str.str();
577 std::string _debugName;
578 size_t _debugSummedSize = 0, _debugMeasureCount = 0, _debugReadWaitCount = 0,
579 _debugWriteWaitCount = 0;
583template <
typename Tp>
#define LANE_REGISTER_DEBUG_WRITE_WAIT
#define LANE_REGISTER_DEBUG_INFO
#define LANE_REGISTER_DEBUG_READ_WAIT
#define LANE_REPORT_DEBUG_INFO
The Lane is an efficient cyclic buffer that is synchronized.
std::condition_variable _writing_possible_condition
void immediate_discard(size_t n) noexcept
void emplace(Args &&... args)
Write a single element by constructing it.
Lane(const Lane< Tp > &source)=delete
bool is_end() const
True when write_end() was called.
void move_write(value_type *elements, size_t n)
void clear() noexcept
Clear the contents and reset the state of the Lane.
void swap(Lane< Tp > &other) noexcept
Swap the contents of this Lane with another.
Lane< Tp > & operator=(Lane< Tp > &&source) noexcept
Move assignment.
void wait_for_empty()
Wait until this Lane is empty.
Lane< Tp > & operator=(const Lane< Tp > &source)=delete
void resize(size_t new_capacity)
Change the capacity of the Lane.
void write(value_type &&element)
Write a single element by moving it in.
void immediate_write(T *elements, size_t n) noexcept
This is a template to allow const and non-const (to be able to move).
Lane(Lane< Tp > &&source) noexcept
Move construct a Lane.
size_t capacity() const noexcept
Tp value_type
Type of elements stored in the Lane.
void write(const value_type *elements, size_t n)
enum casacore::aocommon::Lane::@165250377254016164334045006074227223211343376364 _status
size_t discard(size_t n)
This method does the same thing as read(buffer, n) but discards the data.
std::size_t size_type
Integer type used to store size types.
size_t read_position() const noexcept
void write_generic(T *elements, size_t n)
This is a template to allow const and non-const (to be able to move).
void write(const value_type &element)
Write a single element.
size_t read(value_type *destinations, size_t n)
std::condition_variable _reading_possible_condition
Lane(size_t capacity)
Construct a Lane with the given capacity.
size_t free_read_space() const noexcept
bool is_end_and_empty() const
True when write_end() and the lane does not contain items.
void immediate_read(value_type *elements, size_t n) noexcept
bool read(value_type &destination)
Lane() noexcept
Construct a Lane with zero elements.
void swap(aocommon::Lane< Tp > &first, aocommon::Lane< Tp > &second) noexcept
LatticeExprNode round(const LatticeExprNode &expr)