Skip to content
Snippets Groups Projects
Commit 4228bfb7 authored by Charles Leggett's avatar Charles Leggett
Browse files

Made StatEntity more thread safe

See merge request !275
parents d19e41b9 d98db978
Branches
Tags
1 merge request!275Made StatEntity more thread safe
Pipeline #
......@@ -7,6 +7,7 @@
// ============================================================================
#include <string>
#include <iostream>
#include <mutex>
// ============================================================================
// Gaudi
// ============================================================================
......@@ -83,6 +84,10 @@ public:
const double flag2 ,
const double minFlag ,
const double maxFlag ) ;
/// copy constructor
StatEntity ( const StatEntity& );
/// assignment operator
StatEntity& operator= ( const StatEntity& );
/// destructor
~StatEntity () = default;
// ==========================================================================
......@@ -439,6 +444,8 @@ private:
double m_se_maximalFlag ;
// DR number of calls before reset
long m_se_nEntriesBeforeReset ;
// Mutex to protect calls of add/reset/operator++
std::mutex m_mutex;
// ==========================================================================
};
// ============================================================================
......
......@@ -55,6 +55,30 @@ StatEntity::StatEntity
, m_se_nEntriesBeforeReset ( -1 )
{}
// ============================================================================
// The copy contructor, non default because of atomics
// ============================================================================
StatEntity::StatEntity
( const StatEntity& other )
: m_se_nEntries ( other.m_se_nEntries )
, m_se_accumulatedFlag ( other.m_se_accumulatedFlag )
, m_se_accumulatedFlag2 ( other.m_se_accumulatedFlag2 )
, m_se_minimalFlag ( other.m_se_minimalFlag )
, m_se_maximalFlag ( other.m_se_maximalFlag )
, m_se_nEntriesBeforeReset ( other.m_se_nEntriesBeforeReset )
{}
// ============================================================================
// The copy contructor, non default because of atomics
// ============================================================================
StatEntity& StatEntity::operator=
( const StatEntity& other ) {
m_se_nEntries = other.m_se_nEntries;
m_se_accumulatedFlag = other.m_se_accumulatedFlag;
m_se_accumulatedFlag2 = other.m_se_accumulatedFlag2;
m_se_minimalFlag = other.m_se_minimalFlag;
m_se_maximalFlag = other.m_se_maximalFlag;
m_se_nEntriesBeforeReset = other.m_se_nEntriesBeforeReset;
return *this;
}// ============================================================================
// the internal format description
// ============================================================================
const std::string& StatEntity::format()
......@@ -148,6 +172,7 @@ double StatEntity::efficiencyErr () const
// ============================================================================
StatEntity& StatEntity::operator+=( const StatEntity& other )
{
std::lock_guard<std::mutex> guard(m_mutex);
m_se_nEntries += other.m_se_nEntries ;
m_se_accumulatedFlag += other.m_se_accumulatedFlag ;
m_se_accumulatedFlag2 += other.m_se_accumulatedFlag2 ;
......@@ -185,6 +210,7 @@ bool StatEntity::operator< ( const StatEntity& se ) const
// ============================================================================
unsigned long StatEntity::add ( const double Flag )
{
std::lock_guard<std::mutex> guard(m_mutex);
//
if ( 0 < m_se_nEntriesBeforeReset ) { --m_se_nEntriesBeforeReset; }
else if ( 0 == m_se_nEntriesBeforeReset ) { reset(); } ///< reset everything
......@@ -205,6 +231,7 @@ unsigned long StatEntity::add ( const double Flag )
// ============================================================================
void StatEntity::reset()
{
std::lock_guard<std::mutex> guard(m_mutex);
//
m_se_nEntries = 0 ;
m_se_accumulatedFlag = 0 ;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment