Changeset 158:9dfbc0672376 in finroc_plugins_data_ports
- Timestamp:
- 04.05.2020 23:46:17 (4 years ago)
- Branch:
- 17.03
- Parents:
- 155:784bc286a24d (diff), 157:7de85ed96fec (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent. - Phase:
- public
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
common/tPortBufferPool.h
r137 r158 166 166 if (buffer) 167 167 { 168 return std::move(buffer);168 return buffer; 169 169 } 170 170 return possibly_create_buffer ? CreateBuffer(data_type) : tPointer(); … … 182 182 if (buffer) 183 183 { 184 return std::move(buffer);184 return buffer; 185 185 } 186 186 return CreateBuffer(buffer_size); -
common/tPortBufferPool.h
r157 r158 58 58 namespace data_ports 59 59 { 60 61 //---------------------------------------------------------------------- 62 // Forward declarations / typedefs / enums 63 //---------------------------------------------------------------------- 64 namespace standard 65 { 66 class tPortBufferManager; 67 } 68 60 69 namespace common 61 70 { 62 63 //----------------------------------------------------------------------64 // Forward declarations / typedefs / enums65 //----------------------------------------------------------------------66 71 67 72 //---------------------------------------------------------------------- … … 109 114 tBufferPoolSingleThreaded, tBufferPoolConcurrent >::type tBufferPool; 110 115 116 /*! Whether this is a buffer pool for a standard port */ 117 enum { cSTANDARD_PORT = std::is_same<TBufferManager, standard::tPortBufferManager>::value }; 118 119 /*! Information what kind of content buffers contain (either data type - or buffer size) */ 120 typedef typename std::conditional<cSTANDARD_PORT, rrlib::rtti::tType, uint32_t>::type tContentId; 121 111 122 //---------------------------------------------------------------------- 112 123 // Public methods and typedefs … … 118 129 119 130 /*! 120 * \param data_type Type of buffers in pool121 * \param intial_size Number of buffer to allocate initially122 */ 123 tPortBufferPool(const rrlib::rtti::tType& data_type, int initial_size) :131 * \param buffer_content Buffer content 132 * \param intial_size Number of buffers to allocate initially 133 */ 134 tPortBufferPool(const tContentId& buffer_content, int initial_size) : 124 135 buffer_pool() 125 136 { 126 AllocateAdditionalBuffers( data_type, std::max<size_t>(initial_size, tBufferPool::MinUnusedBuffersRequired()));137 AllocateAdditionalBuffers(buffer_content, std::max<size_t>(initial_size, tBufferPool::MinUnusedBuffersRequired())); 127 138 } 128 139 … … 133 144 * Allocates the specified number of additional buffers and adds them to pool 134 145 * 135 * \param data_type Data type of buffers to add146 * \param buffer_content Buffer content 136 147 * \param count Number of buffers to allocate and add 137 148 */ 138 inline void AllocateAdditionalBuffers(const rrlib::rtti::tType& data_type, size_t count)149 inline void AllocateAdditionalBuffers(const tContentId& buffer_content, size_t count) 139 150 { 140 151 for (size_t i = 0; i < count; i++) 141 152 { 142 CreateBuffer(data_type); 143 } 144 } 145 146 // /*! 147 // * \return Data Type of buffers in pool 148 // */ 149 // inline rrlib::rtti::tType GetDataType() const 150 // { 151 // return data_type; 152 // } 153 154 /*! 155 * \param cheaply_copyable_type_index Index of 'cheaply copied' data type of pool 153 CreateBuffer(buffer_content); 154 } 155 } 156 157 /*! 158 * \param data_type Data type of desired buffer 159 * \param possibly_create_buffer Create new buffer if there is none in pool at the moment? 156 160 * \return Returns unused buffer. If there are no buffers that can be reused, a new buffer is allocated. 157 161 */ 158 inline tPointer GetUnusedBuffer(uint32_t cheaply_copyable_type_index) 162 template <bool Tstandard_port = cSTANDARD_PORT> 163 inline tPointer GetUnusedBuffer(const typename std::enable_if<Tstandard_port, rrlib::rtti::tType>::type& data_type, bool possibly_create_buffer = true) 159 164 { 160 165 tPointer buffer = buffer_pool.GetUnusedBuffer(); … … 163 168 return buffer; 164 169 } 165 return CreateBuffer(optimized::GetType(cheaply_copyable_type_index)); 166 } 167 168 /*! 169 * \param data_type Data type of buffers in this pool 170 * \param possibly_create_buffer Create new buffer if there is none in pool at the moment? 171 * \return Returns unused buffer. If there are no buffers that can be reused, a new buffer is possibly allocated. 172 */ 173 inline tPointer GetUnusedBuffer(const rrlib::rtti::tType& data_type, bool possibly_create_buffer = true) 170 return possibly_create_buffer ? CreateBuffer(data_type) : tPointer(); 171 } 172 173 /*! 174 * \param buffer_size Size of buffer 175 * \param data_type Data type of desired buffer 176 * \return Returns unused buffer. If there are no buffers that can be reused, a new buffer is allocated. 177 */ 178 template <bool Tstandard_port = cSTANDARD_PORT> 179 inline tPointer GetUnusedBuffer(typename std::enable_if < !Tstandard_port, uint32_t >::type buffer_size, const rrlib::rtti::tType& data_type) 174 180 { 175 181 tPointer buffer = buffer_pool.GetUnusedBuffer(); … … 178 184 return buffer; 179 185 } 180 return possibly_create_buffer ? CreateBuffer(data_type) : tPointer();186 return CreateBuffer(buffer_size); 181 187 } 182 188 … … 193 199 //---------------------------------------------------------------------- 194 200 private: 195 196 /*! Data Type of buffers in pool */197 //const rrlib::rtti::tType data_type; This information would be redundant198 201 199 202 /*! Wrapped buffer pool */ … … 202 205 203 206 /* 204 * \param data_type Data type of buffers in this pool207 * \param buffer_content Buffer content 205 208 * \return Create new buffer/instance of port data and add to pool 206 209 */ 207 tPointer CreateBuffer(const rrlib::rtti::tType& data_type)208 { 209 std::unique_ptr<TBufferManager> new_buffer(TBufferManager::CreateInstance( data_type));210 tPointer CreateBuffer(const tContentId& buffer_content) 211 { 212 std::unique_ptr<TBufferManager> new_buffer(TBufferManager::CreateInstance(buffer_content)); 210 213 211 214 // In case we have a string: allocate a certain buffer size (for RT capabilities with smaller payload) - 212 215 // We do not need this check for 'cheaply copied' types - therefore the concurrency condition 213 if ( CONCURRENCY != rrlib::concurrent_containers::tConcurrency::NONE&& new_buffer->GetObject().GetType().GetRttiName() == typeid(tString).name())216 if (cSTANDARD_PORT && new_buffer->GetObject().GetType().GetRttiName() == typeid(tString).name()) 214 217 { 215 218 static_cast<rrlib::rtti::tGenericObject&>(new_buffer->GetObject()).GetData<tString>().reserve(512); // TODO: move to parameter in some config.h … … 217 220 return buffer_pool.AddBuffer(std::move(new_buffer)); 218 221 } 219 220 222 }; 221 223
Note: See TracChangeset
for help on using the changeset viewer.