Changeset 137:a51ce184f4f2 in finroc_plugins_data_ports


Ignore:
Timestamp:
02.10.2018 11:55:19 (2 months ago)
Author:
Max Reichardt <max.reichardt@…>
Branch:
17.03
Parents:
135:fd179b075769 (diff), 136:c3e65240f9fd (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
Tags:
tip
Message:

Merge with 17.03

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • common/tPortBufferPool.h

    r130 r137  
    135135    buffer_pool() 
    136136  { 
    137     AllocateAdditionalBuffers(buffer_content, initial_size); 
     137    AllocateAdditionalBuffers(buffer_content, std::max<size_t>(initial_size, tBufferPool::MinUnusedBuffersRequired())); 
    138138  } 
    139139 
  • common/tPortBufferPool.h

    r136 r137  
    5858namespace data_ports 
    5959{ 
     60 
     61//---------------------------------------------------------------------- 
     62// Forward declarations / typedefs / enums 
     63//---------------------------------------------------------------------- 
     64namespace standard 
     65{ 
     66class tPortBufferManager; 
     67} 
     68 
    6069namespace common 
    6170{ 
    62  
    63 //---------------------------------------------------------------------- 
    64 // Forward declarations / typedefs / enums 
    65 //---------------------------------------------------------------------- 
    6671 
    6772//---------------------------------------------------------------------- 
     
    109114          tBufferPoolSingleThreaded, tBufferPoolConcurrent >::type tBufferPool; 
    110115 
     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 
    111122//---------------------------------------------------------------------- 
    112123// Public methods and typedefs 
     
    118129 
    119130  /*! 
    120    * \param data_type Type of buffers in pool 
    121    * \param intial_size Number of buffer to allocate initially 
    122    */ 
    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) : 
    124135    buffer_pool() 
    125136  { 
    126     AllocateAdditionalBuffers(data_type, std::max<size_t>(initial_size, tBufferPool::MinUnusedBuffersRequired())); 
     137    AllocateAdditionalBuffers(buffer_content, std::max<size_t>(initial_size, tBufferPool::MinUnusedBuffersRequired())); 
    127138  } 
    128139 
     
    133144   * Allocates the specified number of additional buffers and adds them to pool 
    134145   * 
    135    * \param data_type Data type of buffers to add 
     146   * \param buffer_content Buffer content 
    136147   * \param count Number of buffers to allocate and add 
    137148   */ 
    138   inline void AllocateAdditionalBuffers(const rrlib::rtti::tType& data_type, size_t count) 
     149  inline void AllocateAdditionalBuffers(const tContentId& buffer_content, size_t count) 
    139150  { 
    140151    for (size_t i = 0; i < count; i++) 
    141152    { 
    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? 
    156160   * \return Returns unused buffer. If there are no buffers that can be reused, a new buffer is allocated. 
    157161   */ 
    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) 
    159164  { 
    160165    tPointer buffer = buffer_pool.GetUnusedBuffer(); 
     
    163168      return std::move(buffer); 
    164169    } 
    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) 
    174180  { 
    175181    tPointer buffer = buffer_pool.GetUnusedBuffer(); 
     
    178184      return std::move(buffer); 
    179185    } 
    180     return possibly_create_buffer ? CreateBuffer(data_type) : tPointer(); 
     186    return CreateBuffer(buffer_size); 
    181187  } 
    182188 
     
    193199//---------------------------------------------------------------------- 
    194200private: 
    195  
    196   /*! Data Type of buffers in pool */ 
    197   //const rrlib::rtti::tType data_type;  This information would be redundant 
    198201 
    199202  /*! Wrapped buffer pool */ 
     
    202205 
    203206  /* 
    204    * \param data_type Data type of buffers in this pool 
     207   * \param buffer_content Buffer content 
    205208   * \return Create new buffer/instance of port data and add to pool 
    206209   */ 
    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)); 
    210213 
    211214    // In case we have a string: allocate a certain buffer size (for RT capabilities with smaller payload) - 
    212215    // 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()) 
    214217    { 
    215218      static_cast<rrlib::rtti::tGenericObject&>(new_buffer->GetObject()).GetData<tString>().reserve(512);  // TODO: move to parameter in some config.h 
     
    217220    return buffer_pool.AddBuffer(std::move(new_buffer)); 
    218221  } 
    219  
    220222}; 
    221223 
Note: See TracChangeset for help on using the changeset viewer.