wifi: prevent static initialization order issue with m_staticPhyEntities

Co-authored-by: Stefano Avallone <stavallo@gmail.com>
This commit is contained in:
Gabriel Ferreira
2021-09-16 08:22:50 -03:00
parent 942f57c762
commit 62ab4ade42
2 changed files with 16 additions and 9 deletions

View File

@@ -286,7 +286,6 @@ const std::set<FrequencyChannelInfo> WifiPhy::m_frequencyChannels =
{ std::make_tuple (207, 6975, 160, WIFI_PHY_OFDM_CHANNEL, WIFI_PHY_BAND_6GHZ) }
};
std::map<WifiModulationClass, Ptr<PhyEntity> > WifiPhy::m_staticPhyEntities; //will be filled by g_constructor_XXX
TypeId
WifiPhy::GetTypeId (void)
@@ -620,6 +619,13 @@ WifiPhy::DoDispose (void)
m_phyEntities.clear ();
}
std::map<WifiModulationClass, Ptr<PhyEntity> > &
WifiPhy::GetStaticPhyEntities (void)
{
static std::map<WifiModulationClass, Ptr<PhyEntity> > g_staticPhyEntities;
return g_staticPhyEntities;
}
Ptr<WifiPhyStateHelper>
WifiPhy::GetState (void) const
{
@@ -864,8 +870,8 @@ WifiPhy::CalculateSnr (const WifiTxVector& txVector, double ber) const
const Ptr<const PhyEntity>
WifiPhy::GetStaticPhyEntity (WifiModulationClass modulation)
{
const auto it = m_staticPhyEntities.find (modulation);
NS_ABORT_MSG_IF (it == m_staticPhyEntities.end (), "Unimplemented Wi-Fi modulation class");
const auto it = GetStaticPhyEntities ().find (modulation);
NS_ABORT_MSG_IF (it == GetStaticPhyEntities ().end (), "Unimplemented Wi-Fi modulation class");
return it->second;
}
@@ -881,15 +887,15 @@ void
WifiPhy::AddStaticPhyEntity (WifiModulationClass modulation, Ptr<PhyEntity> phyEntity)
{
NS_LOG_FUNCTION (modulation);
NS_ASSERT_MSG (m_staticPhyEntities.find (modulation) == m_staticPhyEntities.end (), "The PHY entity has already been added. The setting should only be done once per modulation class");
m_staticPhyEntities[modulation] = phyEntity;
NS_ASSERT_MSG (GetStaticPhyEntities ().find (modulation) == GetStaticPhyEntities ().end (), "The PHY entity has already been added. The setting should only be done once per modulation class");
GetStaticPhyEntities ()[modulation] = phyEntity;
}
void
WifiPhy::AddPhyEntity (WifiModulationClass modulation, Ptr<PhyEntity> phyEntity)
{
NS_LOG_FUNCTION (this << modulation);
NS_ABORT_MSG_IF (m_staticPhyEntities.find (modulation) == m_staticPhyEntities.end (), "Cannot add an unimplemented PHY to supported list. Update the former first.");
NS_ABORT_MSG_IF (GetStaticPhyEntities ().find (modulation) == GetStaticPhyEntities ().end (), "Cannot add an unimplemented PHY to supported list. Update the former first.");
NS_ASSERT_MSG (m_phyEntities.find (modulation) == m_phyEntities.end (), "The PHY entity has already been added. The setting should only be done once per modulation class");
phyEntity->SetOwner (this);
m_phyEntities[modulation] = phyEntity;

View File

@@ -1167,7 +1167,7 @@ protected:
* Add the PHY entity to the map of supported PHY entities for the
* given modulation class for the WifiPhy instance.
* This is a wrapper method used to check that the PHY entity is
* in the static map of implemented PHY entities (\see m_staticPhyEntities).
* in the static map of implemented PHY entities (\see GetStaticPhyEntities).
* In addition, child classes can add their own PHY entities.
*
* \param modulation the modulation class
@@ -1376,12 +1376,13 @@ private:
TracedCallback<Ptr<const Packet>, uint16_t /* frequency (MHz) */, WifiTxVector, MpduInfo, uint16_t /* STA-ID*/> m_phyMonitorSniffTxTrace;
/**
* Map of __implemented__ PHY entities. This is used to compute the different
* \return the map of __implemented__ PHY entities.
* This is used to compute the different
* amendment-specific parameters in a static manner.
* For PHY entities supported by a given WifiPhy instance,
* \see m_phyEntities.
*/
static std::map<WifiModulationClass, Ptr<PhyEntity> > m_staticPhyEntities;
static std::map<WifiModulationClass, Ptr<PhyEntity> > & GetStaticPhyEntities (void);
WifiPhyStandard m_standard; //!< WifiPhyStandard
WifiPhyBand m_band; //!< WifiPhyBand