diff options
author | Zane Shelley <zshelle@us.ibm.com> | 2014-04-07 15:52:41 -0500 |
---|---|---|
committer | A. Patrick Williams III <iawillia@us.ibm.com> | 2014-04-08 16:55:57 -0500 |
commit | ba41c4e29f3a7a6ae5127f80fcbc239e00195a0a (patch) | |
tree | b4c390fade5db0d3aed4ea272074e1c5001bff89 /src/usr/diag/prdf/prdfGlobal.H | |
parent | ed6d7133031da2790f31826f9a5ff99da3a8c963 (diff) | |
download | talos-hostboot-ba41c4e29f3a7a6ae5127f80fcbc239e00195a0a.tar.gz talos-hostboot-ba41c4e29f3a7a6ae5127f80fcbc239e00195a0a.zip |
PRD: global mutex during MDIA functions
Ensures neither PRDF::main(), PRDF::restoreDramRepairs() nor
PRDF::analyzeIplCEStats() are executed at the same time.
Change-Id: Ibb9c824377a99ecfc88d38c812c10f33c1abc830
CQ: SW256002
Backport: release-fips810
Reviewed-on: http://gfw160.aus.stglabs.ibm.com:8080/gerrit/10239
Tested-by: Jenkins Server
Reviewed-by: A. Patrick Williams III <iawillia@us.ibm.com>
Diffstat (limited to 'src/usr/diag/prdf/prdfGlobal.H')
-rw-r--r-- | src/usr/diag/prdf/prdfGlobal.H | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/src/usr/diag/prdf/prdfGlobal.H b/src/usr/diag/prdf/prdfGlobal.H index 33203931a..6f3a16548 100644 --- a/src/usr/diag/prdf/prdfGlobal.H +++ b/src/usr/diag/prdf/prdfGlobal.H @@ -37,6 +37,7 @@ /*--------------------------------------------------------------------*/ #include <prdfGlobal_common.H> #include <util/singleton.H> +#include <sys/sync.h> // for mutex support /*--------------------------------------------------------------------*/ /* Singleton macros common to both FSP and Hostboot */ @@ -95,4 +96,112 @@ typedef uint32_t hwTableContent; */ const uint32_t CONTENT_HW = 0x40000000; +/** + * @brief This class provides general purpose mutual + * exclusion (mutex) class for locking static or + * member data to ensure thread safety. + */ +class prdfMutex +{ +public: + + /** + * Constructor + */ + prdfMutex(); + + /** + * Destructor + */ + ~prdfMutex(); + + /** + * Lock this mutex + */ + void lock(); + + /** + * Unlock this mutex + */ + void unlock(); + +private: + mutex_t ivMutex; + + // No copies or assignments allowed + prdfMutex(prdfMutex& r); + prdfMutex& operator=(prdfMutex& r); +}; + +inline prdfMutex::prdfMutex() +{ + mutex_init(&ivMutex); +} + +inline prdfMutex::~prdfMutex() +{ + mutex_destroy(&ivMutex); +} + +inline void prdfMutex::lock() +{ + mutex_lock( &ivMutex ); +} + +inline void prdfMutex::unlock() +{ + mutex_unlock( &ivMutex ); +} + +/** + * @brief This class provides interfaces to + * acquire a scope mutex + */ +class prdfScopeMutex +{ +public: + /** + * Constructor (locks the specified mutex) + * + * @param i_mutex the mutex to be locked + * for the scope of this function + */ + prdfScopeMutex(prdfMutex& i_mutex); + + /** + * Destructor + */ + ~prdfScopeMutex(); + +private: + prdfMutex* ivMutex; + + // No copies or assignments allowed + prdfScopeMutex(prdfScopeMutex& r); + prdfScopeMutex& operator=(prdfScopeMutex& r); +}; + +inline prdfScopeMutex::prdfScopeMutex(prdfMutex& i_mutex) +: ivMutex(&i_mutex) +{ + ivMutex->lock(); +} + +inline prdfScopeMutex::~prdfScopeMutex() +{ + ivMutex->unlock(); +} + +/** + * @brief Mutex to prevent concurrent accesses + * + */ +static prdfMutex g_mutex; + +/** + * @brief macro to acquire global scope mutex + */ +#define PRDF_SYSTEM_SCOPE_MUTEX \ + prdfScopeMutex dataLock(g_mutex); + #endif // PRDF_GLOBAL_HB_H |