Changeset 69:78f5c1180404 in finroc_plugins_data_ports


Ignore:
Timestamp:
24.06.2014 19:24:53 (5 years ago)
Author:
Max Reichardt <mreichardt@…>
Branch:
default
Phase:
public
Message:

Added single-threaded cheap copy port implementation

Files:
3 added
18 edited

Legend:

Unmodified
Added
Removed
  • api/tBoundedPort.h

    r63 r69  
    4646#include "plugins/data_ports/tPortCreationInfo.h" 
    4747#include "plugins/data_ports/optimized/tCheapCopyPort.h" 
     48#include "plugins/data_ports/api/tSingleThreadedCheapCopyPort.h" 
    4849 
    4950//---------------------------------------------------------------------- 
     
    7172 */ 
    7273template <typename T, tPortImplementationType TYPE> 
    73 class tBoundedPort : public optimized::tCheapCopyPort 
    74 { 
    75   static_assert((!std::is_integral<T>::value) || TYPE == tPortImplementationType::NUMERIC, "Type must be numeric for numeric type"); 
     74class tBoundedPort : public std::conditional<definitions::cSINGLE_THREADED, api::tSingleThreadedCheapCopyPort<T>, optimized::tCheapCopyPort>::type 
     75{ 
     76  static_assert((!std::is_integral<T>::value) || TYPE == tPortImplementationType::NUMERIC || definitions::cSINGLE_THREADED, "Type must be numeric for numeric type"); 
    7677 
    7778  typedef typename std::conditional<TYPE == tPortImplementationType::NUMERIC, numeric::tNumber, T>::type tBufferType; 
    7879  typedef tPortImplementation<T, TYPE> tImplementationVariation; 
     80  typedef typename std::conditional<definitions::cSINGLE_THREADED, api::tSingleThreadedCheapCopyPort<T>, optimized::tCheapCopyPort>::type tPortBase; 
    7981 
    8082//---------------------------------------------------------------------- 
     
    8486 
    8587  tBoundedPort(const tPortCreationInfo<T>& creation_info) : 
    86     optimized::tCheapCopyPort(AdjustCreationInfo(creation_info)), 
     88    tPortBase(AdjustCreationInfo(creation_info)), 
    8789    bounds(creation_info.GetBounds()) 
    8890  { 
     
    105107  inline void SetBounds(const tBounds<T>& new_bounds) 
    106108  { 
    107     if (IsReady()) 
     109    if (this->IsReady()) 
    108110    { 
    109111      FINROC_LOG_PRINT(WARNING, "Port has already been initialized. Cannot change bounds."); 
     
    111113    } 
    112114    bounds = new_bounds; 
     115#ifndef RRLIB_SINGLE_THREADED 
    113116    tBufferType value_buffer = tBufferType(); 
    114     CopyCurrentValue(value_buffer, tStrategy::NEVER_PULL); 
    115     T value = tImplementationVariation::ToValue(value_buffer, GetUnit()); 
    116     if (!bounds.InBounds(value)) 
    117     { 
    118       tUnusedManagerPointer new_buffer(optimized::tGlobalBufferPools::Instance().GetUnusedBuffer(GetCheaplyCopyableTypeIndex()).release()); 
    119       tImplementationVariation::Assign(new_buffer->GetObject().GetData<tBufferType>(), bounds.GetOutOfBoundsDefault(), GetUnit()); 
    120       BrowserPublishRaw(new_buffer); // If port is already connected, could this have undesirable side-effects? (I do not think so - otherwise we need to do something more sophisticated here) 
    121     } 
     117    this->CopyCurrentValue(value_buffer, tStrategy::NEVER_PULL); 
     118    T value = tImplementationVariation::ToValue(value_buffer, this->GetUnit()); 
     119    if (!bounds.InBounds(value)) 
     120    { 
     121      typename tPortBase::tUnusedManagerPointer new_buffer(optimized::tGlobalBufferPools::Instance().GetUnusedBuffer(this->GetCheaplyCopyableTypeIndex()).release()); 
     122      tImplementationVariation::Assign(new_buffer->GetObject().template GetData<tBufferType>(), bounds.GetOutOfBoundsDefault(), this->GetUnit()); 
     123      this->BrowserPublishRaw(new_buffer); // If port is already connected, could this have undesirable side-effects? (I do not think so - otherwise we need to do something more sophisticated here) 
     124    } 
     125#else 
     126    T value = this->CurrentValue(); 
     127    if (!bounds.InBounds(value)) 
     128    { 
     129      T new_value = bounds.GetOutOfBoundsDefault(); 
     130      BrowserPublishRaw(rrlib::rtti::tGenericObjectWrapper<T>(new_value), rrlib::time::cNO_TIME); 
     131    } 
     132#endif 
    122133  } 
    123134 
     
    135146  inline static tPortCreationInfo<T> AdjustCreationInfo(tPortCreationInfo<T> creation_info) 
    136147  { 
    137     creation_info.flags |= tFrameworkElement::tFlag::NON_STANDARD_ASSIGN; 
     148    creation_info.flags |= core::tFrameworkElement::tFlag::NON_STANDARD_ASSIGN; 
    138149    return creation_info; 
    139150  } 
    140151 
    141   virtual std::string BrowserPublishRaw(tUnusedManagerPointer& buffer, bool notify_listener_on_this_port = true, 
     152#ifndef RRLIB_SINGLE_THREADED 
     153  virtual std::string BrowserPublishRaw(typename tPortBase::tUnusedManagerPointer& buffer, bool notify_listener_on_this_port = true, 
    142154                                        tChangeStatus change_constant = tChangeStatus::CHANGED) override 
    143155  { 
    144     if (buffer->GetObject().GetType() != GetDataType()) 
     156    if (buffer->GetObject().GetType() != this->GetDataType()) 
    145157    { 
    146158      return "Buffer has wrong type"; 
    147159    } 
    148     const tBufferType& value_buffer = buffer->GetObject().GetData<tBufferType>(); 
    149     T value = tImplementationVariation::ToValue(value_buffer, GetUnit()); 
     160    const tBufferType& value_buffer = buffer->GetObject().template GetData<tBufferType>(); 
     161    T value = tImplementationVariation::ToValue(value_buffer, this->GetUnit()); 
    150162    if (!bounds.InBounds(value)) 
    151163    { 
    152164      return GenerateErrorMessage(value); 
    153165    } 
    154     return tCheapCopyPort::BrowserPublishRaw(buffer, notify_listener_on_this_port, change_constant); 
    155   } 
     166    return tPortBase::BrowserPublishRaw(buffer, notify_listener_on_this_port, change_constant); 
     167  } 
     168#else 
     169  virtual std::string BrowserPublishRaw(const rrlib::rtti::tGenericObject& buffer, rrlib::time::tTimestamp timestamp, 
     170                                        bool notify_listener_on_this_port = true, tChangeStatus change_constant = tChangeStatus::CHANGED) override 
     171  { 
     172    if (buffer.GetType() != this->GetDataType()) 
     173    { 
     174      return "Buffer has wrong type"; 
     175    } 
     176    T value = buffer.template GetData<T>(); 
     177    if (!bounds.InBounds(value)) 
     178    { 
     179      return GenerateErrorMessage(value); 
     180    } 
     181    return tPortBase::BrowserPublishRaw(buffer, timestamp, notify_listener_on_this_port, change_constant); 
     182  } 
     183 
     184#endif 
    156185 
    157186  /*! 
     
    174203  } 
    175204 
    176   virtual bool NonStandardAssign(tPublishingDataGlobalBuffer& publishing_data, tChangeStatus change_constant) override 
     205#ifndef RRLIB_SINGLE_THREADED 
     206  virtual bool NonStandardAssign(typename tPortBase::tPublishingDataGlobalBuffer& publishing_data, tChangeStatus change_constant) override 
    177207  { 
    178208    return NonStandardAssignImplementation(publishing_data, change_constant); 
    179209  } 
    180210 
    181   virtual bool NonStandardAssign(tPublishingDataThreadLocalBuffer& publishing_data, tChangeStatus change_constant) override 
     211  virtual bool NonStandardAssign(typename tPortBase::tPublishingDataThreadLocalBuffer& publishing_data, tChangeStatus change_constant) override 
    182212  { 
    183213    return NonStandardAssignImplementation(publishing_data, change_constant); 
    184214  } 
     215 
    185216 
    186217  template <typename TPublishingData> 
     
    188219  { 
    189220    const tBufferType& value_buffer = publishing_data.published_buffer->GetObject().template GetData<tBufferType>(); 
    190     T value = tImplementationVariation::ToValue(value_buffer, GetUnit()); 
     221    T value = tImplementationVariation::ToValue(value_buffer, this->GetUnit()); 
    191222    if (!bounds.InBounds(value)) 
    192223    { 
     
    196227      } 
    197228      rrlib::time::tTimestamp timestamp = publishing_data.published_buffer->GetTimestamp(); 
    198       tUnusedManagerPointer buffer = GetUnusedBuffer(publishing_data); 
     229      typename tPortBase::tUnusedManagerPointer buffer = this->GetUnusedBuffer(publishing_data); 
    199230      publishing_data.Init(buffer); 
    200231      tImplementationVariation::Assign(publishing_data.published_buffer->GetObject().template GetData<tBufferType>(), 
    201                                        bounds.GetOutOfBoundsAction() == tOutOfBoundsAction::ADJUST_TO_RANGE ? bounds.ToBounds(value) : bounds.GetOutOfBoundsDefault(), GetUnit()); 
     232                                       bounds.GetOutOfBoundsAction() == tOutOfBoundsAction::ADJUST_TO_RANGE ? bounds.ToBounds(value) : bounds.GetOutOfBoundsDefault(), this->GetUnit()); 
    202233      publishing_data.published_buffer->SetTimestamp(timestamp); 
    203234    } 
    204     return tCheapCopyPort::NonStandardAssign(publishing_data, change_constant); 
     235    return tPortBase::NonStandardAssign(publishing_data, change_constant); 
    205236    // tCheapCopyPort::Assign(publishing_data); done anyway 
    206237  } 
     238 
     239#else 
     240 
     241  virtual bool NonStandardAssign(typename tPortBase::tPublishingData& publishing_data, tChangeStatus change_constant) override 
     242  { 
     243    T value = publishing_data.template Value<T>(); 
     244    if (!bounds.InBounds(value)) 
     245    { 
     246      if (bounds.GetOutOfBoundsAction() == tOutOfBoundsAction::DISCARD) 
     247      { 
     248        return false; 
     249      } 
     250 
     251      *static_cast<T*>(this->current_value.data_pointer) = bounds.GetOutOfBoundsAction() == tOutOfBoundsAction::ADJUST_TO_RANGE ? bounds.ToBounds(value) : bounds.GetOutOfBoundsDefault(); 
     252      this->current_value.timestamp = publishing_data.value->timestamp; 
     253      publishing_data.value = &this->current_value; 
     254    } 
     255    return tPortBase::NonStandardAssign(publishing_data, change_constant); 
     256  } 
     257 
     258#endif 
    207259}; 
    208260 
  • api/tGenericPortImplementation.cpp

    r63 r69  
    108108  typedef api::tPortImplementation<T, api::tPortImplementationTypeTrait<T>::type> tImplementation; 
    109109 
    110   typedef optimized::tCheapCopyPort tPortBase; 
     110  typedef typename tImplementation::tPortBase tPortBase; 
    111111 
    112112  virtual core::tAbstractPort* CreatePort(const common::tAbstractDataPortCreationInfo& creation_info) override 
     
    124124  { 
    125125    tPortBase& port = static_cast<tPortBase&>(abstract_port); 
    126     if ((strategy == tStrategy::DEFAULT && port.PushStrategy()) || strategy == tStrategy::NEVER_PULL) 
     126    if ((strategy == tStrategy::DEFAULT && port.PushStrategy()) || strategy == tStrategy::NEVER_PULL || definitions::cSINGLE_THREADED) 
    127127    { 
    128128      tPortDataPointer<rrlib::rtti::tGenericObject> buffer = this->GetUnusedBuffer(port); 
     
    132132      return std::move(buffer); 
    133133    } 
     134#ifndef RRLIB_SINGLE_THREADED 
    134135    else 
    135136    { 
     
    137138      return tPortDataPointerImplementation<rrlib::rtti::tGenericObject, false>(buffer_pointer.release(), false); 
    138139    } 
     140#endif 
    139141  } 
    140142 
     
    155157public: 
    156158 
    157   typedef optimized::tCheapCopyPort tPortBase; 
     159  typedef tCheapCopyPort tPortBase; 
    158160 
    159161  virtual core::tAbstractPort* CreatePort(const common::tAbstractDataPortCreationInfo& creation_info) override 
     
    170172  { 
    171173    tPortBase& port = static_cast<tPortBase&>(abstract_port); 
    172     if ((strategy == tStrategy::DEFAULT && port.PushStrategy()) || strategy == tStrategy::NEVER_PULL) 
     174    if ((strategy == tStrategy::DEFAULT && port.PushStrategy()) || strategy == tStrategy::NEVER_PULL || definitions::cSINGLE_THREADED) 
    173175    { 
    174176      tPortDataPointer<rrlib::rtti::tGenericObject> buffer = this->GetUnusedBuffer(port); 
     
    178180      return std::move(buffer); 
    179181    } 
     182#ifndef RRLIB_SINGLE_THREADED 
    180183    else 
    181184    { 
     
    183186      return tPortDataPointerImplementation<rrlib::rtti::tGenericObject, false>(buffer_pointer.release(), false); 
    184187    } 
     188#endif 
    185189  } 
    186190 
    187191  virtual void Publish(core::tAbstractPort& port, const rrlib::rtti::tGenericObject& data, const rrlib::time::tTimestamp& timestamp) override 
    188192  { 
     193#ifndef RRLIB_SINGLE_THREADED 
    189194    assert(data.GetType() == port.GetDataType()); 
    190195    optimized::tThreadLocalBufferPools* thread_local_pools = optimized::tThreadLocalBufferPools::Get(); 
     
    205210      publish_operation.Execute<false, tChangeStatus::CHANGED, false, false>(static_cast<tPortBase&>(port)); 
    206211    } 
     212#else 
     213    static_cast<tPortBase&>(port).Publish(data, timestamp); 
     214#endif 
    207215  } 
    208216 
     
    310318  if (IsCheaplyCopiedType(port.GetDataType())) 
    311319  { 
    312     static_cast<optimized::tCheapCopyPort&>(port).SetPullRequestHandler(pull_request_handler); 
     320    static_cast<tCheapCopyPort&>(port).SetPullRequestHandler(pull_request_handler); 
    313321  } 
    314322  else 
  • api/tGenericPortImplementation.h

    r46 r69  
    7676class tGenericPortImplementation : public rrlib::rtti::tTypeAnnotation 
    7777{ 
    78  
    7978//---------------------------------------------------------------------- 
    8079// Public methods and typedefs 
    8180//---------------------------------------------------------------------- 
    8281public: 
     82 
     83  typedef typename std::conditional<definitions::cSINGLE_THREADED, optimized::tSingleThreadedCheapCopyPortGeneric, optimized::tCheapCopyPort>::type tCheapCopyPort; 
    8384 
    8485  /*! 
     
    113114  const rrlib::rtti::tGenericObject* GetDefaultValue(core::tAbstractPort& port) 
    114115  { 
    115     return IsCheaplyCopiedType(port.GetDataType()) ? static_cast<optimized::tCheapCopyPort&>(port).GetDefaultValue() : static_cast<standard::tStandardPort&>(port).GetDefaultValue(); 
     116    return IsCheaplyCopiedType(port.GetDataType()) ? static_cast<tCheapCopyPort&>(port).GetDefaultValue() : static_cast<standard::tStandardPort&>(port).GetDefaultValue(); 
    116117  } 
    117118 
     
    142143    if (IsCheaplyCopiedType(port.GetDataType())) 
    143144    { 
    144       optimized::tCheapCopyPort& cc_port = static_cast<optimized::tCheapCopyPort&>(port); 
     145      tCheapCopyPort& cc_port = static_cast<tCheapCopyPort&>(port); 
    145146      if (optimized::tThreadLocalBufferPools::Get()) 
    146147      { 
  • api/tPortBufferReturnCustomization.h

    r46 r69  
    108108}; 
    109109 
     110// plain-type implementation 
     111template <typename T> 
     112struct tPortBufferReturnCustomizationSingleThreaded 
     113{ 
     114  typedef typename std::remove_const<T>::type tPortDataType; 
     115 
     116  template <typename U> 
     117  static T ToDesiredType(const U& u) 
     118  { 
     119    return u.first; 
     120  } 
     121}; 
     122 
     123// tPortDataPointer<T> implementation 
     124template <typename T> 
     125struct tPortBufferReturnCustomizationSingleThreaded<tPortDataPointer<T>> 
     126{ 
     127  typedef typename std::remove_const<T>::type tPortDataType; 
     128 
     129  template <typename U> 
     130  static tPortDataPointer<T> ToDesiredType(const U& u) 
     131  { 
     132    return tPortDataPointer<T>(api::tPortDataPointerImplementation<tPortDataType, true>(u.first, u.second)); 
     133  } 
     134}; 
     135 
    110136//---------------------------------------------------------------------- 
    111137// End of namespace declaration 
  • api/tPortDataPointerImplementation.h

    r67 r69  
    196196  } 
    197197 
     198#ifndef RRLIB_SINGLE_THREADED 
    198199  inline tPortDataPointerImplementation(typename tPortImplementation::tPortBase::tLockingManagerPointer& pointer, optimized::tCheapCopyPort& port) : 
    199200    buffer(tPortImplementation::ToValue(pointer->GetObject().template GetData<typename tPortImplementation::tPortBuffer>(), port.GetUnit())), 
     
    202203  { 
    203204  } 
     205#else 
     206  inline tPortDataPointerImplementation(const typename optimized::tSingleThreadedCheapCopyPortGeneric::tCurrentValueBuffer& value) : 
     207    buffer(*static_cast<T*>(value.data_pointer)), 
     208    timestamp(value.timestamp), 
     209    null_pointer(false) 
     210  { 
     211  } 
     212 
     213  inline tPortDataPointerImplementation(typename tPortImplementation::tPortBase::tLockingManagerPointer& pointer, api::tSingleThreadedCheapCopyPort<T>& port) : 
     214    buffer(pointer.implementation.buffer), 
     215    timestamp(pointer.implementation.timestamp), 
     216    null_pointer(pointer.implementation.null_pointer) 
     217  { 
     218  } 
     219 
     220#endif 
    204221 
    205222  inline tPortDataPointerImplementation(const T& value, const rrlib::time::tTimestamp timestamp) : 
     
    334351        { 
    335352          // recycle unused buffer 
     353#ifndef RRLIB_SINGLE_THREADED 
    336354          typename optimized::tCheapCopyPort::tUnusedManagerPointer::deleter_type deleter; 
    337           deleter(static_cast<optimized::tCheaplyCopiedBufferManager*>(buffer_manager)); 
     355#else 
     356          typename optimized::tGlobalBufferPools::tBufferPointer::deleter_type deleter; 
     357#endif 
     358          deleter(static_cast<optimized::tGlobalBufferPools::tBufferType*>(buffer_manager)); 
    338359        } 
    339360        else 
     
    349370        { 
    350371          // reduce reference counter 
     372#ifndef RRLIB_SINGLE_THREADED 
    351373          typename optimized::tCheapCopyPort::tLockingManagerPointer::deleter_type deleter; 
    352           deleter(static_cast<optimized::tCheaplyCopiedBufferManager*>(buffer_manager)); 
     374#else 
     375          typename optimized::tGlobalBufferPools::tBufferPointer::deleter_type deleter; 
     376#endif 
     377          deleter(static_cast<optimized::tGlobalBufferPools::tBufferType*>(buffer_manager)); 
    353378        } 
    354379        else 
  • api/tPortImplementation.h

    r67 r69  
    4949#include "plugins/data_ports/numeric/tNumber.h" 
    5050#include "plugins/data_ports/optimized/tCheapCopyPort.h" 
     51#include "plugins/data_ports/api/tSingleThreadedCheapCopyPort.h" 
    5152#include "plugins/data_ports/standard/tStandardPort.h" 
    5253 
     
    8182struct tCheapCopyPortBaseImplementation 
    8283{ 
    83   typedef optimized::tCheapCopyPort tPortBase; 
     84  typedef typename std::conditional<definitions::cSINGLE_THREADED, api::tSingleThreadedCheapCopyPort<TBuffer>, optimized::tCheapCopyPort>::type tPortBase; 
    8485 
    8586  static core::tAbstractPort* CreatePort(tPortCreationInfo<TWrapper> creation_info) 
     
    9394    else 
    9495    { 
    95       return new optimized::tCheapCopyPort(creation_info); 
     96      return new tPortBase(creation_info); 
    9697    } 
    9798  } 
     
    102103struct tCheapCopyPortBaseImplementation<TWrapper, TBuffer, TYPE, false> 
    103104{ 
    104   typedef optimized::tCheapCopyPort tPortBase; 
     105  typedef typename std::conditional<definitions::cSINGLE_THREADED, api::tSingleThreadedCheapCopyPort<TBuffer>, optimized::tCheapCopyPort>::type tPortBase; 
    105106 
    106107  static core::tAbstractPort* CreatePort(tPortCreationInfo<TWrapper> creation_info) 
     
    111112      FINROC_LOG_PRINT(WARNING, "Bounds are not supported for type '", creation_info.data_type.GetName(), "'. Ignoring."); 
    112113    } 
    113     return new optimized::tCheapCopyPort(creation_info); 
     114    return new tPortBase(creation_info); 
    114115  } 
    115116}; 
     
    194195struct tPortImplementation : public tCheapCopyPortImplementation<T, TYPE> 
    195196{ 
     197#ifndef RRLIB_SINGLE_THREADED 
    196198  typedef tCheapCopyPortImplementation<T, TYPE> tBase; 
    197199 
     
    264266    port.SetDefault(wrapper); 
    265267  } 
     268#endif 
     269}; 
     270 
     271// implementation for cheap copy types in single-threaded mode 
     272template <typename T> 
     273struct tPortImplementation<T, tPortImplementationType::CHEAP_COPY_SINGLE_THREADED> : 
     274  public tCheapCopyPortBaseImplementation<T, T, tPortImplementationType::CHEAP_COPY_SINGLE_THREADED, IsBoundable<T>::value> 
     275{ 
     276  typedef api::tSingleThreadedCheapCopyPort<T> tPortBase; 
     277  typedef T tPortBuffer; 
     278 
     279  static inline void CopyCurrentPortValue(tPortBase& port, T& result_buffer, rrlib::time::tTimestamp& timestamp_buffer) 
     280  { 
     281    timestamp_buffer = port.CurrentValueTimestamp(); 
     282    result_buffer = port.CurrentValue(); 
     283  } 
     284 
     285  static inline void CopyAndPublish(tPortBase& port, const T& data, const rrlib::time::tTimestamp& timestamp) 
     286  { 
     287    port.Publish(data, timestamp); 
     288  } 
     289 
     290  static inline tPortDataPointer<const T> GetPointer(tPortBase& port) 
     291  { 
     292    return tPortDataPointerImplementation<T, true>(port.CurrentValueBuffer()); 
     293  } 
     294 
     295  static void SetDefault(tPortBase& port, const T& new_default) 
     296  { 
     297    T t = new_default; 
     298    rrlib::rtti::tGenericObjectWrapper<T> wrapper(t); 
     299    port.SetDefault(wrapper); 
     300  } 
    266301}; 
    267302 
  • api/tPortImplementationTypeTrait.h

    r63 r69  
    6767  STANDARD, 
    6868  CHEAP_COPY, 
    69   NUMERIC 
     69  NUMERIC, 
     70  CHEAP_COPY_SINGLE_THREADED 
    7071}; 
    7172 
     
    8182{ 
    8283  /*! Port implementation to use */ 
    83   static const tPortImplementationType type = IsNumeric<T>::value ? tPortImplementationType::NUMERIC : 
    84       (tIsCheaplyCopiedType<T>::value ? tPortImplementationType::CHEAP_COPY : tPortImplementationType::STANDARD); 
     84  static const tPortImplementationType type = (IsNumeric<T>::value && (!definitions::cSINGLE_THREADED)) ? tPortImplementationType::NUMERIC : 
     85      (tIsCheaplyCopiedType<T>::value ? (definitions::cSINGLE_THREADED ? tPortImplementationType::CHEAP_COPY_SINGLE_THREADED : 
     86                                         tPortImplementationType::CHEAP_COPY) : tPortImplementationType::STANDARD); 
    8587}; 
    8688 
  • api/tPortListenerAdapter.h

    r59 r69  
    161161}; 
    162162 
     163// Normal adapter class for cheap copy types (single-threaded) 
     164template <typename LISTENER, typename T, bool FIRST_LISTENER> 
     165class tPortListenerAdapter<LISTENER, T, tPortImplementationType::CHEAP_COPY_SINGLE_THREADED, FIRST_LISTENER> : public tPortListenerAdapterBase<LISTENER, FIRST_LISTENER> 
     166{ 
     167public: 
     168 
     169  template <typename ... TArgs> 
     170  tPortListenerAdapter(LISTENER& listener, TArgs& ... args) : tPortListenerAdapterBase<LISTENER, FIRST_LISTENER>(listener, args...) {} 
     171 
     172private: 
     173 
     174  virtual void PortChangedRaw(tChangeContext& change_context, int& lock_counter, rrlib::buffer_pools::tBufferManagementInfo& value) override 
     175  { 
     176    this->PortChangedRawBase(change_context, lock_counter, value); 
     177    this->listener.OnPortChange(static_cast<optimized::tSingleThreadedCheapCopyPortGeneric::tCurrentValueBuffer&>(value).data->GetData<T>(), change_context); 
     178  } 
     179}; 
     180 
    163181// Normal adapter class for generic port 
    164182template <typename LISTENER, bool FIRST_LISTENER> 
     
    177195    if (IsCheaplyCopiedType(change_context.Origin().GetDataType())) 
    178196    { 
    179       this->listener.OnPortChange(static_cast<optimized::tCheaplyCopiedBufferManager&>(value).GetObject(), change_context); 
     197      if (definitions::cSINGLE_THREADED) 
     198      { 
     199        this->listener.OnPortChange(*static_cast<optimized::tSingleThreadedCheapCopyPortGeneric::tCurrentValueBuffer&>(value).data, change_context); 
     200      } 
     201      else 
     202      { 
     203        this->listener.OnPortChange(static_cast<optimized::tCheaplyCopiedBufferManager&>(value).GetObject(), change_context); 
     204      } 
    180205    } 
    181206    else 
     
    197222private: 
    198223 
    199   typedef typename std::conditional<tIsCheaplyCopiedType<T>::value, optimized::tCheaplyCopiedBufferManager, standard::tPortBufferManager>::type tBufferManager; 
     224  typedef typename std::conditional<tIsCheaplyCopiedType<T>::value, typename std::conditional<definitions::cSINGLE_THREADED, optimized::tSingleThreadedCheapCopyPortGeneric::tCurrentValueBuffer, optimized::tCheaplyCopiedBufferManager>::type, standard::tPortBufferManager>::type tBufferManager; 
    200225  typedef tPortImplementation<T, tPortImplementationTypeTrait<T>::type> tImplementation; 
    201226 
     
    222247    this->listener.OnPortChange(pointer, change_context); 
    223248  } 
     249 
     250  inline void PortChangedRawImplementation(tChangeContext& change_context, int& lock_counter, optimized::tSingleThreadedCheapCopyPortGeneric::tCurrentValueBuffer& value) 
     251  { 
     252    tPortDataPointer<const T> pointer(tPortDataPointerImplementation<T, true>(value.data->GetData<T>(), change_context.Timestamp())); 
     253    this->listener.OnPortChange(pointer, change_context); 
     254  } 
    224255}; 
    225256 
     
    241272    if (IsCheaplyCopiedType(change_context.Origin().GetDataType())) 
    242273    { 
    243       tPortDataPointer<const rrlib::rtti::tGenericObject> pointer( 
    244         api::tPortDataPointerImplementation<rrlib::rtti::tGenericObject, false>(static_cast<optimized::tCheaplyCopiedBufferManager*>(&value), false)); 
    245       this->listener.OnPortChange(pointer, change_context); 
     274      if (definitions::cSINGLE_THREADED) 
     275      { 
     276        optimized::tSingleThreadedCheapCopyPortGeneric::tCurrentValueBuffer& buffer = static_cast<optimized::tSingleThreadedCheapCopyPortGeneric::tCurrentValueBuffer&>(value); 
     277        auto buffer_manager = optimized::tGlobalBufferPools::Instance().GetUnusedBuffer(buffer.cheaply_copyable_type_index); 
     278        buffer_manager->GetObject().DeepCopyFrom(*buffer.data); 
     279        tPortDataPointer<const rrlib::rtti::tGenericObject> pointer( 
     280          api::tPortDataPointerImplementation<rrlib::rtti::tGenericObject, false>(buffer_manager.release(), false)); 
     281        this->listener.OnPortChange(pointer, change_context); 
     282      } 
     283      else 
     284      { 
     285        tPortDataPointer<const rrlib::rtti::tGenericObject> pointer( 
     286          api::tPortDataPointerImplementation<rrlib::rtti::tGenericObject, false>(static_cast<optimized::tCheaplyCopiedBufferManager*>(&value), false)); 
     287        this->listener.OnPortChange(pointer, change_context); 
     288      } 
    246289    } 
    247290    else 
  • optimized/tCheapCopyPort.cpp

    r46 r69  
    7070// Implementation 
    7171//---------------------------------------------------------------------- 
     72#ifndef RRLIB_SINGLE_THREADED 
    7273 
    7374namespace internal 
     
    538539} 
    539540 
     541#endif // RRLIB_SINGLE_THREADED 
     542 
    540543//---------------------------------------------------------------------- 
    541544// End of namespace declaration 
  • optimized/tCheapCopyPort.h

    r63 r69  
    8787class tCheapCopyPort : public common::tAbstractDataPort 
    8888{ 
     89#ifndef RRLIB_SINGLE_THREADED 
     90 
    8991  template<typename T> 
    9092  friend class finroc::data_ports::tPort; 
     
    164166 
    165167  /*! 
    166    * \param creation_info PortCreationInformation 
     168   * \param creation_info Port creation information 
    167169   */ 
    168170  tCheapCopyPort(common::tAbstractDataPortCreationInfo creation_info); 
     
    970972    } 
    971973  } 
     974#else 
     975 
     976public: 
     977  inline tUnit GetUnit() 
     978  { 
     979    return tUnit::cNO_UNIT; 
     980  } 
     981 
     982#endif // RRLIB_SINGLE_THREADED 
    972983}; 
    973984 
  • optimized/tGlobalBufferPools.h

    r46 r69  
    6767 * Global set of buffer pools for 'cheaply copied' types. 
    6868 */ 
    69 class tGlobalBufferPools : public tThreadSpecificBufferPools<true> 
     69class tGlobalBufferPools : public tThreadSpecificBufferPools < !definitions::cSINGLE_THREADED > 
    7070{ 
    7171 
  • optimized/tThreadLocalBufferManager.cpp

    r46 r69  
    7373  tCheaplyCopiedBufferManager(tThreadLocalBufferPools::Get()) 
    7474{ 
    75   assert(GetThreadLocalOrigin()); 
     75  assert(GetThreadLocalOrigin() || definitions::cSINGLE_THREADED); 
    7676} 
    7777 
  • optimized/tThreadLocalBufferPools.cpp

    r46 r69  
    120120  tInitRegularDeleteTask() 
    121121  { 
     122#ifndef RRLIB_SINGLE_THREADED 
    122123    core::internal::tGarbageDeleter::AddRegularTask(DeleteGarbage); 
     124#endif 
    123125  } 
    124126}; 
  • standard/tStandardPort.cpp

    r59 r69  
    4343#include "plugins/data_ports/standard/tMultiTypePortBufferPool.h" 
    4444#include "plugins/data_ports/optimized/tCheapCopyPort.h" 
     45#include "plugins/data_ports/optimized/tSingleThreadedCheapCopyPortGeneric.h" 
    4546#include "plugins/data_ports/standard/tPullRequestHandlerRaw.h" 
    4647 
     
    8485    core::tPortWrapperBase::tConstructorArguments<common::tAbstractDataPortCreationInfo> creation_info(port_name, &parent, type, flags); 
    8586    return IsCheaplyCopiedType(type) ? // TODO: put it 
    86            *static_cast<core::tAbstractPort*>(new optimized::tCheapCopyPort(creation_info)) : 
     87#ifndef RRLIB_SINGLE_THREADED 
     88           * static_cast<core::tAbstractPort*>(new optimized::tCheapCopyPort(creation_info)) : 
     89#else 
     90           *static_cast<core::tAbstractPort*>(new optimized::tSingleThreadedCheapCopyPortGeneric(creation_info)) : 
     91#endif 
    8792           *static_cast<core::tAbstractPort*>(new tStandardPort(creation_info)); 
    8893    //return *static_cast<core::tAbstractPort*>(new tStandardPort(creation_info)); 
  • tGenericPort.h

    r62 r69  
    166166    if (IsCheaplyCopiedType(pointer->GetType())) 
    167167    { 
     168#ifndef RRLIB_SINGLE_THREADED 
    168169      typename optimized::tCheapCopyPort::tUnusedManagerPointer pointer2(static_cast<optimized::tCheaplyCopiedBufferManager*>(pointer.implementation.Release())); 
    169170      return static_cast<optimized::tCheapCopyPort*>(GetWrapped())->BrowserPublishRaw(pointer2, notify_listener_on_this_port, change_constant); 
     171#else 
     172      return static_cast<optimized::tSingleThreadedCheapCopyPortGeneric*>(GetWrapped())->BrowserPublishRaw(*pointer, pointer.GetTimestamp(), notify_listener_on_this_port, change_constant); 
     173#endif 
    170174    } 
    171175    else 
  • tPort.h

    r64 r69  
    182182  inline T Get(typename std::enable_if<AVAILABLE, void>::type* v = NULL) const 
    183183  { 
     184#ifndef RRLIB_SINGLE_THREADED 
    184185    tPortBuffer t; 
    185186    GetWrapped()->CopyCurrentValue(t); 
    186187    return tImplementation::ToValue(t, GetWrapped()->GetUnit()); 
     188#else 
     189    return GetWrapped()->CurrentValue(); 
     190#endif 
    187191  } 
    188192 
     
    190194  inline T Get(typename std::enable_if<AVAILABLE, rrlib::time::tTimestamp&>::type& timestamp) const 
    191195  { 
     196#ifndef RRLIB_SINGLE_THREADED 
    192197    tPortBuffer t; 
    193198    GetWrapped()->CopyCurrentValue(t, timestamp); 
    194199    return tImplementation::ToValue(t, GetWrapped()->GetUnit()); 
     200#else 
     201    timestamp = GetWrapped()->CurrentTimestamp(); 
     202    return GetWrapped()->CurrentValue(); 
     203#endif 
    195204  } 
    196205 
  • tPortBuffers.h

    r46 r69  
    6868 *           Can alternatively be tPortDataPointer<const ...> to get pointer to buffer. 
    6969 */ 
    70 template <typename T> 
     70template < typename T, bool Tsingle_threaded_cheap_copy = tIsCheaplyCopiedType<typename api::tPortBufferReturnCustomizationSingleThreaded<T>::tPortDataType>::value && definitions::cSINGLE_THREADED > 
    7171class tPortBuffers : private rrlib::util::tNoncopyable 
    7272{ 
     
    159159}; 
    160160 
     161template <typename T> 
     162class tPortBuffers<T, true> : private rrlib::util::tNoncopyable 
     163{ 
     164  /*! Class that contains implementation of buffer access */ 
     165  typedef api::tPortBufferReturnCustomizationSingleThreaded<T> tImplementation; 
     166  typedef api::tSingleThreadedCheapCopyPort<typename tImplementation::tPortDataType> tPortBase; 
     167  typedef typename tPortBase::tQueue tQueue; 
     168  typedef typename tPortBase::tQueueEntry tQueueEntry; 
     169 
     170//---------------------------------------------------------------------- 
     171// Public methods and typedefs 
     172//---------------------------------------------------------------------- 
     173public: 
     174 
     175  tPortBuffers(tQueue& queue, tPortBase& port) : 
     176    queue(queue) 
     177  { 
     178  } 
     179 
     180  /*! Move constructor */ 
     181  tPortBuffers(tPortBuffers && other) : 
     182    queue() 
     183  { 
     184    std::swap(queue, other.queue); 
     185  } 
     186 
     187  /*! Move assignment */ 
     188  tPortBuffers& operator=(tPortBuffers && other) 
     189  { 
     190    std::swap(queue, other.queue); 
     191    return *this; 
     192  } 
     193 
     194  /*! 
     195   * \return True, if there are no elements (left) in this fragment. 
     196   */ 
     197  bool Empty() 
     198  { 
     199    return queue.empty(); 
     200  } 
     201 
     202  /*! 
     203   * Returns and removes the element from queue fragment that was enqueued first 
     204   * (the first call possibly involves reverting the element order => a little overhead) 
     205   * 
     206   * \return Element that was removed 
     207   */ 
     208  T PopFront() 
     209  { 
     210    tQueueEntry temp = queue.front(); 
     211    queue.pop_front(); 
     212    return tImplementation::template ToDesiredType<tQueueEntry>(temp); 
     213  } 
     214 
     215  /*! 
     216   * Returns and removes the element from queue fragment that was enqueued last 
     217   * (the first call possibly involves reverting the element order => a little overhead) 
     218   * 
     219   * \return Element that was removed 
     220   */ 
     221  T PopBack() 
     222  { 
     223    tQueueEntry temp = queue.back(); 
     224    queue.pop_back(); 
     225    return tImplementation::template ToDesiredType<tQueueEntry>(temp); 
     226  } 
     227 
     228  /*! 
     229   * Returns and removes an element from the queue fragment 
     230   * 
     231   * \return Element that was removed 
     232   */ 
     233  T PopAny() 
     234  { 
     235    return PopFront(); 
     236  } 
     237 
     238//---------------------------------------------------------------------- 
     239// Private fields and methods 
     240//---------------------------------------------------------------------- 
     241private: 
     242 
     243  /*! Reference to port's queue */ 
     244  tQueue queue; 
     245}; 
     246 
    161247//---------------------------------------------------------------------- 
    162248// End of namespace declaration 
  • tPortDataPointer.h

    r46 r69  
    190190private: 
    191191 
     192 
    192193  friend struct api::tPortImplementation<tPortData, api::tPortImplementationTypeTrait<tPortData>::type>; 
    193194  friend class tGenericPort; 
     
    195196  friend class api::tPullRequestHandlerAdapter; 
    196197  friend class api::tPullRequestHandlerAdapterGeneric; 
     198  template <typename U, bool CHEAPLY_COPIED_TYPE> 
     199  friend class api::tPortDataPointerImplementation; 
    197200 
    198201  template <typename U> 
Note: See TracChangeset for help on using the changeset viewer.