Replaced ported prdfScanFacility.[HC]
The ScanFacility was just a bunch of wrapper functions for the
flyweights. I eliminated the wrappers by making singletons for each
flyweight.
Signed-off-by: Zane Shelley <zshelle@us.ibm.com>
Change-Id: I8ff96f33da2d52e2c1abc3556d094dabcf441945
diff --git a/src/isolator/hei_isolator.cpp b/src/isolator/hei_isolator.cpp
index aea45df..b09f16a 100644
--- a/src/isolator/hei_isolator.cpp
+++ b/src/isolator/hei_isolator.cpp
@@ -1,6 +1,7 @@
#include <isolator/hei_isolator.hpp>
#include <register/hei_hardware_register.hpp>
+#include <util/hei_flyweight.hpp>
namespace libhei
{
@@ -27,6 +28,9 @@
// BEGIN temporary code
HEI_INF( "Isolator::uninitialize()" );
// END temporary code
+
+ // Remove all of the isolation objects stored in the flyweights.
+ Flyweight<HardwareRegister>::getSingleton().clear();
}
ReturnCode Isolator::isolate( const std::vector<Chip> & i_chipList,
diff --git a/src/register/prdfScanFacility.C b/src/register/prdfScanFacility.C
deleted file mode 100755
index 079efe9..0000000
--- a/src/register/prdfScanFacility.C
+++ /dev/null
@@ -1,233 +0,0 @@
-/* IBM_PROLOG_BEGIN_TAG */
-/* This is an automatically generated prolog. */
-/* */
-/* $Source: src/usr/diag/prdf/common/framework/register/prdfScanFacility.C $ */
-/* */
-/* OpenPOWER HostBoot Project */
-/* */
-/* Contributors Listed Below - COPYRIGHT 2012,2018 */
-/* [+] International Business Machines Corp. */
-/* */
-/* */
-/* Licensed under the Apache License, Version 2.0 (the "License"); */
-/* you may not use this file except in compliance with the License. */
-/* You may obtain a copy of the License at */
-/* */
-/* http://www.apache.org/licenses/LICENSE-2.0 */
-/* */
-/* Unless required by applicable law or agreed to in writing, software */
-/* distributed under the License is distributed on an "AS IS" BASIS, */
-/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or */
-/* implied. See the License for the specific language governing */
-/* permissions and limitations under the License. */
-/* */
-/* IBM_PROLOG_END_TAG */
-
-/**
- @file prdfScanFacility.C
- @brief PRD ScanFaclity class definition
-*/
-//----------------------------------------------------------------------
-// Includes
-//----------------------------------------------------------------------
-
-#include <register/hei_register.hpp>
-#include <util/hei_flyweight.hpp>
-
-#include <prdfScanFacility.H>
-
-namespace libhei
-{
-
-//----------------------------------------------------------------------
-// Constants
-//----------------------------------------------------------------------
-
-//----------------------------------------------------------------------
-// Macros
-//----------------------------------------------------------------------
-
-//----------------------------------------------------------------------
-// Internal Function Prototypes
-//----------------------------------------------------------------------
-
-//----------------------------------------------------------------------
-// Global Variables
-//----------------------------------------------------------------------
-
-NullRegister AttnTypeRegister::cv_null(1024);
-
-//---------------------------------------------------------------------
-// Member Function Specifications
-//---------------------------------------------------------------------
-
-
-ScanFacility & ScanFacility::Access(void)
-{
- static ScanFacility sf;
- return sf;
-}
-//-----------------------------------------------------------------------------
-Register & ScanFacility::GetScanCommRegister( uint64_t address,
- uint32_t i_scomLength, TARGETING::TYPE i_type,
- Register::AccessLevel i_regOp )
-{
- /* i_regOp is not used to determine uniqueness of the object for following
- reason -
- There can not be two registers in hardware with same address and target
- type supporting different operations say one supports only write and
- other both read and write.
- */
-
- HardwareRegister scrKey( address, i_scomLength, i_type, i_regOp );
- // in case we get a object with different default operation, we shall reset
- // it to what it should be as per rule file.
- HardwareRegister ®Created = iv_scomRegFw.get(scrKey);
- regCreated.setAccessLevel( i_regOp );
- return regCreated;
-}
-
-//------------------------------------------------------------------------------
-
-Register & ScanFacility::GetNotRegister(
- Register & i_arg )
-{
- NotRegister r(i_arg);
- return iv_notRegFw.get(r);
-}
-
-//-----------------------------------------------------------------------------
-
-Register & ScanFacility::GetLeftShiftRegister(
- Register & i_arg,
- uint16_t i_amount )
-{
- LeftShiftRegister r(i_arg, i_amount);
- return iv_leftRegFw.get(r);
-}
-
-//-----------------------------------------------------------------------------
-
-Register & ScanFacility::GetSummaryRegister(
- Register & i_arg,
- uint16_t i_bit )
-{
- SummaryRegister r(i_arg, i_bit);
- return iv_sumRegFw.get(r);
-}
-
-//------------------------------------------------------------------------------
-
-Register & ScanFacility::GetRightShiftRegister(
- Register & i_arg,
- uint16_t i_amount )
-{
- RightShiftRegister r(i_arg, i_amount);
- return iv_rightRegFw.get(r);
-}
-
-
-//------------------------------------------------------------------------------
-
-Register & ScanFacility::GetAndRegister(
- Register & i_left,
- Register & i_right )
-{
- AndRegister r(i_left,i_right);
- return iv_andRegFw.get(r);
-}
-
-//------------------------------------------------------------------------------
-
-Register & ScanFacility::GetOrRegister(
- Register & i_left,
- Register & i_right )
-{
- OrRegister r(i_left,i_right);
- return iv_orRegFw.get(r);
-}
-
-//-----------------------------------------------------------------------------
-
-Register & ScanFacility::GetAttnTypeRegister(
- Register * i_check,
- Register * i_recov,
- Register * i_special,
- Register * i_proccs,
- Register * i_hostattn )
-{
- AttnTypeRegister r(i_check, i_recov, i_special, i_proccs, i_hostattn);
- return iv_attnRegFw.get(r);
-}
-
-//------------------------------------------------------------------------------
-
-Register & ScanFacility::GetConstantRegister(
- const BitStringBuffer & i_val )
-{
- ConstantRegister r(i_val);
- return iv_constRegFw.get(r);
-}
-//------------------------------------------------------------------------------
-Register & ScanFacility::GetPluginRegister(
- Register & i_flyweight,
- ExtensibleChip & i_RuleChip )
-{
- ScomRegisterAccess l_regKey ( i_flyweight,&i_RuleChip );
- return iv_pluginRegFw.get(l_regKey);
-
-}
-//-----------------------------------------------------------------------------
-void ScanFacility::ResetPluginRegister()
-{
- iv_pluginRegFw.clear();
-
-
-}
-
-//-----------------------------------------------------------------------------
-
-void ScanFacility::reset()
-{
- iv_scomRegFw.clear();
- iv_attnRegFw.clear();
- iv_andRegFw.clear();
- iv_orRegFw.clear();
- iv_notRegFw.clear();
- iv_leftRegFw.clear();
- iv_sumRegFw.clear();
- iv_rightRegFw.clear();
- iv_constRegFw.clear();
- iv_pluginRegFw.clear();
-}
-
-//------------------------------------------------------------------------------
-#ifdef FLYWEIGHT_PROFILING
-void ScanFacility::printStats()
-{
- PRDF_TRAC("HardwareRegister");
- iv_scomRegFw.printStats();
- PRDF_TRAC("Not Register");
- iv_notRegFw.printStats();
- PRDF_TRAC("Left Register");
- iv_leftRegFw.printStats();
- PRDF_TRAC("Right Register");
- iv_rightRegFw.printStats();
- PRDF_TRAC("And Register");
- iv_andRegFw.printStats();
- PRDF_TRAC("Or Register");
- iv_orRegFw.printStats();
- PRDF_TRAC("AttnTypeRegisters FW" );
- iv_attnRegFw.printStats();
- PRDF_TRAC("SummaryRegisters FW" );
- iv_sumRegFw.printStats();
- PRDF_TRAC("ConstantRegisters FW" );
- iv_constRegFw.printStats();
- PRDF_TRAC("PluginRegisters FW" );
- iv_pluginRegFw.printStats();
-}
-
-#endif
-
-} // end namespace libhei
-
diff --git a/src/register/prdfScanFacility.H b/src/register/prdfScanFacility.H
deleted file mode 100755
index 1b22e16..0000000
--- a/src/register/prdfScanFacility.H
+++ /dev/null
@@ -1,232 +0,0 @@
-/* IBM_PROLOG_BEGIN_TAG */
-/* This is an automatically generated prolog. */
-/* */
-/* $Source: src/usr/diag/prdf/common/framework/register/prdfScanFacility.H $ */
-/* */
-/* OpenPOWER HostBoot Project */
-/* */
-/* Contributors Listed Below - COPYRIGHT 2012,2018 */
-/* [+] International Business Machines Corp. */
-/* */
-/* */
-/* Licensed under the Apache License, Version 2.0 (the "License"); */
-/* you may not use this file except in compliance with the License. */
-/* You may obtain a copy of the License at */
-/* */
-/* http://www.apache.org/licenses/LICENSE-2.0 */
-/* */
-/* Unless required by applicable law or agreed to in writing, software */
-/* distributed under the License is distributed on an "AS IS" BASIS, */
-/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or */
-/* implied. See the License for the specific language governing */
-/* permissions and limitations under the License. */
-/* */
-/* IBM_PROLOG_END_TAG */
-
-#ifndef PRDFSCANFACILITY_H
-#define PRDFSCANFACILITY_H
-/**
- @file prdfScanFacility.H
- @brief Description
-*/
-
-
-//--------------------------------------------------------------------
-// Includes
-//--------------------------------------------------------------------
-
-#include <register/hei_hardware_register.hpp>
-#include <register/hei_operator_register.hpp>
-#include <util/hei_flyweight.hpp>
-
-#include <vector>
-#include <prdfPlatServices.H>
-
-namespace libhei
-{
-
-
-/**
- PRD Scan Facility
- @author Doug Gilbert
- @par The Scan facility is used by PRD to access Scan and Scan Comm
- @ functions.It attempts to reduce duplicate objects and their
- @ aggragates as must as possible.
-*/
-class ScanFacility
-{
-public:
- /**
- The Scan Facility is a singleton - this function provides access to it.
- */
- static ScanFacility & Access(void);
-
- /**
- * @brief Returns reference to flyweight object of type HardwareRegister.
- * An object of given address is first searched in flyweight.
- * If object exist, reference to existing object is returned
- * else a new one is created.
- * @param i_address address of the register
- * @param i_scomLength length of the bit string
- * @param i_type type of target associated with register
- * @param i_regOp operations supported for given register
- * @return returns reference to flyweight object from factory
- */
- Register & GetScanCommRegister( uint64_t address,
- uint32_t i_scomLength, TARGETING::TYPE i_type,
- Register::AccessLevel i_regOp );
-
- /**
- * @brief Get a register that bitwise inverts the bitstring of a register
- * when read or written to
- * @param Register source
- * @post Only one instance of the register with this SCR parameter will
- * exist
- */
- Register & GetNotRegister(Register & i_arg);
-
- /**
- * @brief Get a register that bitwise left shift the bitstring of a register
- * when read or written to
- * @param Register source
- * @post Only one instance of the register with this SCR parameter and
- * amount will exist
- */
- Register & GetLeftShiftRegister(
- Register & i_arg, uint16_t i_amount);
-
- /**
- * @brief Get a register that bitwise right shift the bitstring of a register
- * when read or written to
- * @param Register source
- * @post Only one instance of the register with this SCR parameter and amount
- * @ will exist
- */
- Register & GetRightShiftRegister(
- Register & i_arg, uint16_t i_amount);
-
- /**
- * @brief Get a register for the summary construct
- * @param Register source
- * @param uint16_t i_bit bit to set if any attentions found in i_arg
- * @post Only one instance of the register with this SCR parameter and
- * amount will exist
- */
- Register & GetSummaryRegister(
- Register & i_arg, uint16_t i_bit);
-
- /**
- * @brief Get a register that bit-wise ANDs the bitstring of two register
- * when read or written to
- * @param The 2 SCR 's to AND
- * @posrt Only one instance of the register with these SCRs will exist
- */
- Register & GetAndRegister(Register & i_left,
- Register & i_right);
-
- /**
- * @brief Get a register that bitwise ORs the bitstrings of two register when
- * read or written
- * @param the 2 SCR's to OR
- * @post Only one instance of the register with these SCR's will exist
- */
- Register & GetOrRegister(Register & i_left,
- Register & i_right);
-
- /**
- * @brief Get a AttnTypeRegister
- * @params 5 pointers to scr Registers
- * @post only one instance of the register with these SCR's will exist
- */
- Register & GetAttnTypeRegister(
- Register * i_check,
- Register * i_recov,
- Register * i_special,
- Register * i_proccs,
- Register * i_hostattn );
-
- /**
- * @brief Get a PrdfConstantRegister
- * @param BitString - the bit string constant to use.
- * @post only one instance of the register with this BIT_STRING value will
- * exist.
- */
- Register & GetConstantRegister(const BitStringBuffer & i_val);
- /**
- * @brief Get a plugin register
- * @param Reference to target less flyweight object
- * @param RuleChip associatd with register
- * @post only one instance of the register with this BIT_STRING value will
- * exist.
- */
- Register & GetPluginRegister(
- Register & i_flyweight,
- ExtensibleChip & i_RuleChip );
- /**
- * @brief Delete all the plugin register
- * @param None
- * @post all the ScomRegisterAccess register flyweight object created for
- * plugin shall be deleted
- * exist.
- */
- void ResetPluginRegister();
-
- /**
- * @brief Intended to reset all the flyweights if PRD is uninitialized due to
- * a reIPL, reset/reload, or failover. This free up the memory and
- * avoids memory leaks in the flyweights.
- */
- void reset();
-
-#ifdef FLYWEIGHT_PROFILING
-/**
- * @brief prints memory allocated for object residing on flyweight
- */
- void printStats();
-#endif
-
- /**
- Destructor
- */
-// ~ScanFacility();
-private: // functions
- /**
- Constructor
- * @param
- * @returns
- * @pre
- * @post
- * @see
- * @note
- */
- ScanFacility() {}
-
-
-private: // Data
- typedef Flyweight<HardwareRegister> ScanCommRegisters;
- typedef Flyweight<AttnTypeRegister> AttnTypeRegisters;
- typedef Flyweight<AndRegister> AndRegisters;
- typedef Flyweight<OrRegister> OrRegisters;
- typedef Flyweight<NotRegister> NotRegisters;
- typedef Flyweight<LeftShiftRegister> LeftShiftRegisters;
- typedef Flyweight<RightShiftRegister> RightShiftRegisters;
- typedef Flyweight<SummaryRegister> SummaryRegisters;
- typedef Flyweight<ConstantRegister> ConstantRegisters;
- typedef Flyweight<ScomRegisterAccess> PluginRegisters;
-
- ScanCommRegisters iv_scomRegFw;
- AttnTypeRegisters iv_attnRegFw;
- AndRegisters iv_andRegFw;
- OrRegisters iv_orRegFw;
- NotRegisters iv_notRegFw;
- LeftShiftRegisters iv_leftRegFw;
- SummaryRegisters iv_sumRegFw;
- RightShiftRegisters iv_rightRegFw;
- ConstantRegisters iv_constRegFw;
- PluginRegisters iv_pluginRegFw;
-
-};
-
-} // end namespace libhei
-
-#endif /* PRDFSCANFACILITY_H */
diff --git a/src/util/hei_flyweight.hpp b/src/util/hei_flyweight.hpp
index 45d6727..f308e3c 100644
--- a/src/util/hei_flyweight.hpp
+++ b/src/util/hei_flyweight.hpp
@@ -11,7 +11,7 @@
template <class T>
class Flyweight
{
- public:
+ private: // This class cannot be instantiated. Use getSingleton() instead.
/** @brief Default constructor. */
Flyweight() = default;
@@ -25,6 +25,15 @@
/** @brief Default assignment operator. */
Flyweight & operator=( const Flyweight & ) = delete;
+ public:
+
+ /** @brief Provides access to a singleton instance of this object. */
+ static Flyweight & getSingleton()
+ {
+ static Flyweight theFlyweight;
+ return theFlyweight;
+ }
+
/**
* @brief Adds the given entry to the factory, if it does not already
* exist. Then returns a reference to that entry in the factory.
diff --git a/test/flyweight_test.cpp b/test/flyweight_test.cpp
index 1927360..83b33c0 100644
--- a/test/flyweight_test.cpp
+++ b/test/flyweight_test.cpp
@@ -16,12 +16,9 @@
int iv_i = 0;
};
-Flyweight<Foo> factory {};
-
Foo & addFoo( int i )
{
- Foo f { i };
- return factory.get( f );
+ return Flyweight<Foo>::getSingleton().get( Foo { i } );
}
TEST( FlyweightTest, TestSet1 )