summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/gras/CMakeLists.txt1
-rw-r--r--include/gras/block.hpp4
-rw-r--r--include/gras/work_buffer.hpp46
-rw-r--r--include/gras/work_buffer.ipp65
-rw-r--r--lib/block_task.cpp8
5 files changed, 97 insertions, 27 deletions
diff --git a/include/gras/CMakeLists.txt b/include/gras/CMakeLists.txt
index a27ad37..0856942 100644
--- a/include/gras/CMakeLists.txt
+++ b/include/gras/CMakeLists.txt
@@ -18,6 +18,7 @@ install(FILES
thread_pool.hpp
top_block.hpp
work_buffer.hpp
+ work_buffer.ipp
DESTINATION include/gras
COMPONENT ${GRAS_COMP_DEVEL}
diff --git a/include/gras/block.hpp b/include/gras/block.hpp
index 65649b2..5ce207b 100644
--- a/include/gras/block.hpp
+++ b/include/gras/block.hpp
@@ -178,8 +178,8 @@ struct GRAS_API Block : Element
//! Called when the flow graph is stopped, can overload
virtual bool stop(void);
- typedef std::vector<WorkBuffer<const void *> > InputItems;
- typedef std::vector<WorkBuffer<void *> > OutputItems;
+ typedef WorkBufferArray<const void *> InputItems;
+ typedef WorkBufferArray<void *> OutputItems;
//! The official call into the work routine (overload please)
virtual void work(
diff --git a/include/gras/work_buffer.hpp b/include/gras/work_buffer.hpp
index 6695982..ba9972b 100644
--- a/include/gras/work_buffer.hpp
+++ b/include/gras/work_buffer.hpp
@@ -5,13 +5,15 @@
#include <gras/gras.hpp>
#include <cstdlib>
+#include <vector>
namespace gras
{
template <typename PtrType>
-struct WorkBuffer
+class WorkBuffer
{
+public:
//! get a pointer of the desired type to this buffer
template <typename T> T cast(void) const;
@@ -27,40 +29,34 @@ struct WorkBuffer
//! Get the buffer length reference
size_t &size(void);
+private:
PtrType _mem;
size_t _len;
};
-template <typename PtrType> template <typename T>
-inline T WorkBuffer<PtrType>::cast(void) const
-{
- return reinterpret_cast<T>(_mem);
-}
-
template <typename PtrType>
-inline PtrType WorkBuffer<PtrType>::get(void) const
+class WorkBufferArray : public std::vector<WorkBuffer<PtrType> >
{
- return _mem;
-}
+public:
+ //! Get the std::min all item sizes
+ size_t min_items(void) const;
-template <typename PtrType>
-inline PtrType &WorkBuffer<PtrType>::get(void)
-{
- return _mem;
-}
+ //! Get a reference to the min items
+ size_t &min_items(void);
-template <typename PtrType>
-inline size_t WorkBuffer<PtrType>::size(void) const
-{
- return _len;
-}
+ //! Get the std::max of all item sizes
+ size_t max_items(void) const;
-template <typename PtrType>
-inline size_t &WorkBuffer<PtrType>::size(void)
-{
- return _len;
-}
+ //! Get a reference to the max items
+ size_t &max_items(void);
+
+private:
+ size_t _min_items;
+ size_t _max_items;
+};
} //namespace gras
+#include <gras/work_buffer.ipp>
+
#endif /*INCLUDED_GRAS_WORK_BUFFER_HPP*/
diff --git a/include/gras/work_buffer.ipp b/include/gras/work_buffer.ipp
new file mode 100644
index 0000000..c6ca10e
--- /dev/null
+++ b/include/gras/work_buffer.ipp
@@ -0,0 +1,65 @@
+// Copyright (C) by Josh Blum. See LICENSE.txt for licensing information.
+
+#ifndef INCLUDED_GRAS_WORK_BUFFER_IPP
+#define INCLUDED_GRAS_WORK_BUFFER_IPP
+
+namespace gras
+{
+
+template <typename PtrType> template <typename T>
+inline T WorkBuffer<PtrType>::cast(void) const
+{
+ return reinterpret_cast<T>(_mem);
+}
+
+template <typename PtrType>
+inline PtrType WorkBuffer<PtrType>::get(void) const
+{
+ return _mem;
+}
+
+template <typename PtrType>
+inline PtrType &WorkBuffer<PtrType>::get(void)
+{
+ return _mem;
+}
+
+template <typename PtrType>
+inline size_t WorkBuffer<PtrType>::size(void) const
+{
+ return _len;
+}
+
+template <typename PtrType>
+inline size_t &WorkBuffer<PtrType>::size(void)
+{
+ return _len;
+}
+
+template <typename PtrType>
+inline size_t WorkBufferArray<PtrType>::min_items(void) const
+{
+ return _min_items;
+}
+
+template <typename PtrType>
+inline size_t &WorkBufferArray<PtrType>::min_items(void)
+{
+ return _min_items;
+}
+
+template <typename PtrType>
+inline size_t WorkBufferArray<PtrType>::max_items(void) const
+{
+ return _max_items;
+}
+
+template <typename PtrType>
+inline size_t &WorkBufferArray<PtrType>::max_items(void)
+{
+ return _max_items;
+}
+
+} //namespace gras
+
+#endif /*INCLUDED_GRAS_WORK_BUFFER_IPP*/
diff --git a/lib/block_task.cpp b/lib/block_task.cpp
index 2495f01..41f1787 100644
--- a/lib/block_task.cpp
+++ b/lib/block_task.cpp
@@ -125,6 +125,8 @@ void BlockActor::handle_task(void)
//-- initialize input buffers before work
//------------------------------------------------------------------
size_t output_inline_index = 0;
+ this->input_items.min_items() = ~0;
+ this->input_items.max_items() = 0;
for (size_t i = 0; i < num_inputs; i++)
{
this->sort_tags(i);
@@ -137,6 +139,8 @@ void BlockActor::handle_task(void)
this->input_items[i].get() = mem;
this->input_items[i].size() = items;
+ this->input_items.min_items() = std::min(this->input_items.min_items(), items);
+ this->input_items.max_items() = std::max(this->input_items.max_items(), items);
//inline dealings, how and when input buffers can be inlined into output buffers
//continue;
@@ -157,6 +161,8 @@ void BlockActor::handle_task(void)
//------------------------------------------------------------------
//-- initialize output buffers before work
//------------------------------------------------------------------
+ this->output_items.min_items() = ~0;
+ this->output_items.max_items() = 0;
for (size_t i = 0; i < num_outputs; i++)
{
ASSERT(this->output_queues.ready(i));
@@ -167,6 +173,8 @@ void BlockActor::handle_task(void)
this->output_items[i].get() = mem;
this->output_items[i].size() = items;
+ this->output_items.min_items() = std::min(this->output_items.min_items(), items);
+ this->output_items.max_items() = std::max(this->output_items.max_items(), items);
}
//------------------------------------------------------------------