Changeset 72:d0276f64c6d0 in finroc_plugins_network_transport


Ignore:
Timestamp:
15.04.2021 08:39:40 (2 years ago)
Author:
Max Reichardt <max.reichardt@…>
Branch:
17.03
Children:
73:217a300eb4ec, 74:cdad292a2caa
Phase:
public
Message:

Replaces thread-local variable with ScopedContext from finroc_plugins_data_ports

Location:
generic_protocol
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • generic_protocol/tNetworkPortInfo.cpp

    r26 r72  
    6666// Const values 
    6767//---------------------------------------------------------------------- 
    68 __thread tNetworkPortInfo* tNetworkPortInfo::current_publishing_network_port = nullptr; 
    6968 
    7069//---------------------------------------------------------------------- 
     
    127126} 
    128127 
     128bool tNetworkPortInfo::tNetworkPortPublishingContext::Is(const std::type_info& info) 
     129{ 
     130  return info == typeid(tNetworkPortInfo::tNetworkPortPublishingContext); 
     131} 
     132 
    129133//---------------------------------------------------------------------- 
    130134// End of namespace declaration 
  • generic_protocol/tNetworkPortInfo.h

    r52 r72  
    163163  void OnPortChange(data_ports::tPortDataPointer<const rrlib::rtti::tGenericObject>& value, data_ports::tChangeContext& change_context) 
    164164  { 
     165    auto root_context = data_ports::common::tScopedContext::RootContext(); 
     166 
    165167    //FINROC_LOG_PRINT(DEBUG, "Port Changed ", port.GetWrapped()->GetQualifiedName(), " ", rrlib::serialization::Serialize(*value)); 
    166     if (strategy > 0 && (!(current_publishing_network_port && current_publishing_network_port->connection_handle == connection_handle && (&current_publishing_network_port->remote_runtime == &remote_runtime)))) 
     168    if (strategy > 0 && (!(root_context && typeid(*root_context) == typeid(tNetworkPortPublishingContext) && static_cast<tNetworkPortPublishingContext*>(root_context)->current_publishing_network_port.connection_handle == connection_handle && (&static_cast<tNetworkPortPublishingContext*>(root_context)->current_publishing_network_port.remote_runtime == &remote_runtime)))) 
    167169    { 
    168170      remote_runtime.GetLocalRuntimeInfo().OnPortChange(value, this, change_context); 
     
    322324  std::unique_ptr<tNetworkPortInfoClient> client_info; 
    323325 
    324   /*! Network port that currently publishes data using the current thread (null if current thread does not publish data from the net) */ 
    325   static __thread tNetworkPortInfo* current_publishing_network_port; 
     326  class tNetworkPortPublishingContext : public data_ports::common::tScopedContext 
     327  { 
     328  public: 
     329 
     330    tNetworkPortPublishingContext(tNetworkPortInfo& current_publishing_network_port) : 
     331      current_publishing_network_port(current_publishing_network_port) 
     332    { 
     333      assert(tScopedContext::RootContext() == this); 
     334    } 
     335 
     336    /*! Network port that currently publishes data using the current thread (null if current thread does not publish data from the net) */ 
     337    tNetworkPortInfo& current_publishing_network_port; 
     338 
     339    virtual bool Is(const std::type_info& info) override; 
     340  }; 
    326341 
    327342 
  • generic_protocol/tRemoteRuntime.cpp

    r70 r72  
    302302    if (port.first && port.first->IsReady() && data_ports::IsDataFlowType(port.first->GetDataType())) 
    303303    { 
    304       tNetworkPortInfo::current_publishing_network_port = port.second; 
     304      tNetworkPortInfo::tNetworkPortPublishingContext scoped_context(*port.second); 
    305305      data_ports::tGenericPort generic_port = data_ports::tGenericPort::Wrap(*port.first); 
    306306 
     
    347347      while (another_value); 
    348348 
    349       tNetworkPortInfo::current_publishing_network_port = nullptr; 
    350349      message.FinishDeserialize(stream); 
    351350      connection.received_data_after_last_connect = true; 
Note: See TracChangeset for help on using the changeset viewer.