Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the CMS_THREAD_SAFE macro instead of [[cms::thread_safe]] #21480

Merged
merged 4 commits into from Dec 4, 2017
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion Calibration/Tools/interface/EcalRingCalibrationTools.h
Expand Up @@ -15,6 +15,7 @@
#include <atomic>
#include "DataFormats/EcalDetId/interface/EBDetId.h"
#include "DataFormats/EcalDetId/interface/EEDetId.h"
#include "FWCore/Utilities/interface/thread_safety_macros.h"

class DetId;
class CaloGeometry;
Expand Down Expand Up @@ -48,7 +49,7 @@ class EcalRingCalibrationTools

static std::atomic<bool> isInitializedFromGeometry_;

[[cms::thread_guard("isInitializedFromGeometry_")]]
CMS_THREAD_GUARD("isInitializedFromGeometry_")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fwyzard maybe, I am not experienced enough with macros, but given the definition of CMS_THREAD_GUARD, I would rather translate it to this statement:

CMS_THREAD_GUARD(isInitializedFromGeometry_)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point... we are already using both syntaxes e.g. in [1] and [2].
Let me figure out which one is correct and fix the others...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the correct syntax should be:

#define CMS_THREAD_GUARD(_var_) [[cms::thread_guard(#_var_)]]
...
CMS_THREAD_GUARD(isInitializedFromGeometry_)
static short endcapRingIndex_[EEDetId::IX_MAX][EEDetId::IY_MAX];

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The present definition

#define CMS_THREAD_GUARD(_var_) [[cms::thread_guard("#_var_")]]

expands to

[[cms::thread_guard("#_var_")]]

no matter the argument of the macro - which I doubt was the intended behaviour.

static short endcapRingIndex_[EEDetId::IX_MAX][EEDetId::IY_MAX]; // array needed only for the endcaps

static std::once_flag once_;
Expand Down
7 changes: 4 additions & 3 deletions CommonTools/Utils/interface/TMVAEvaluator.h
Expand Up @@ -11,6 +11,7 @@
#include "TMVA/IMethod.h"
#include "CondFormats/EgammaObjects/interface/GBRForest.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/Utilities/interface/thread_safety_macros.h"


class TMVAEvaluator {
Expand All @@ -35,11 +36,11 @@ class TMVAEvaluator {

std::string mMethod;
mutable std::mutex m_mutex;
[[cms::thread_guard("m_mutex")]] std::unique_ptr<TMVA::Reader> mReader;
CMS_THREAD_GUARD("m_mutex") std::unique_ptr<TMVA::Reader> mReader;
std::shared_ptr<const GBRForest> mGBRForest;

[[cms::thread_guard("m_mutex")]] mutable std::map<std::string,std::pair<size_t,float>> mVariables;
[[cms::thread_guard("m_mutex")]] mutable std::map<std::string,std::pair<size_t,float>> mSpectators;
CMS_THREAD_GUARD("m_mutex") mutable std::map<std::string,std::pair<size_t,float>> mVariables;
CMS_THREAD_GUARD("m_mutex") mutable std::map<std::string,std::pair<size_t,float>> mSpectators;
};

#endif // CommonTools_Utils_TMVAEvaluator_h
Expand Down
19 changes: 8 additions & 11 deletions DataFormats/PatCandidates/src/TriggerObjectStandAlone.cc
@@ -1,18 +1,15 @@
//
//

#include "DataFormats/PatCandidates/interface/TriggerObjectStandAlone.h"
#include "FWCore/Common/interface/TriggerNames.h"

#include <boost/algorithm/string.hpp>
#include <tbb/concurrent_unordered_map.h>
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "DataFormats/PatCandidates/interface/libminifloat.h"
#include <boost/algorithm/string.hpp>

#include "DataFormats/Common/interface/TriggerResults.h"
#include "DataFormats/Provenance/interface/ProcessHistory.h"
#include "DataFormats/PatCandidates/interface/TriggerObjectStandAlone.h"
#include "DataFormats/PatCandidates/interface/libminifloat.h"
#include "DataFormats/Provenance/interface/ProcessConfiguration.h"
#include "DataFormats/Provenance/interface/ProcessHistory.h"
#include "FWCore/Common/interface/TriggerNames.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Utilities/interface/thread_safety_macros.h"

using namespace pat;

Expand Down Expand Up @@ -393,7 +390,7 @@ namespace {
}
};
typedef tbb::concurrent_unordered_map<edm::ParameterSetID, std::vector<std::string>, key_hash> AllLabelsMap;
[[cms::thread_safe]] AllLabelsMap allLabelsMap;
CMS_THREAD_SAFE AllLabelsMap allLabelsMap;
}

std::vector<std::string> const* TriggerObjectStandAlone::allLabels(edm::ParameterSetID const& psetid, const edm::EventBase &event,const edm::TriggerResults &res) const {
Expand Down
3 changes: 2 additions & 1 deletion FWCore/Common/src/EventBase.cc
Expand Up @@ -20,6 +20,7 @@
#include "DataFormats/Provenance/interface/ParameterSetID.h"
#include "DataFormats/Common/interface/TriggerResults.h"
#include "FWCore/Utilities/interface/Exception.h"
#include "FWCore/Utilities/interface/thread_safety_macros.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/ParameterSet/interface/Registry.h"

Expand All @@ -30,7 +31,7 @@ namespace {
}
};
typedef tbb::concurrent_unordered_map<edm::ParameterSetID, edm::TriggerNames, key_hash> TriggerNamesMap;
[[cms::thread_safe]] TriggerNamesMap triggerNamesMap;
CMS_THREAD_SAFE TriggerNamesMap triggerNamesMap;
}

namespace edm
Expand Down
3 changes: 2 additions & 1 deletion FWCore/Framework/interface/DataProxy.h
Expand Up @@ -23,6 +23,7 @@
#include <atomic>

// user include files
#include "FWCore/Utilities/interface/thread_safety_macros.h"

// forward declarations
namespace edm {
Expand Down Expand Up @@ -88,7 +89,7 @@ namespace edm {
DataProxy const& operator=(DataProxy const&) = delete; // stop default

// ---------- member data --------------------------------
[[cms::thread_safe]] mutable void const* cache_; //protected by a global mutex
CMS_THREAD_SAFE mutable void const* cache_; //protected by a global mutex
mutable std::atomic<bool> cacheIsValid_;
mutable std::atomic<bool> nonTransientAccessRequested_;
ComponentDescription const* description_;
Expand Down
7 changes: 4 additions & 3 deletions FWCore/MessageLogger/interface/MessageLoggerQ.h
Expand Up @@ -2,6 +2,7 @@
#define FWCore_MessageLogger_MessageLoggerQ_h

#include "FWCore/MessageLogger/interface/ELseverityLevel.h"
#include "FWCore/Utilities/interface/thread_safety_macros.h"

#include <memory>

Expand Down Expand Up @@ -81,9 +82,9 @@ class MessageLoggerQ
void operator = ( MessageLoggerQ const & ) = delete;

// --- data:
[[cms::thread_safe]] static std::shared_ptr<edm::service::AbstractMLscribe> mlscribe_ptr;
[[cms::thread_safe]] static edm::ELseverityLevel threshold;
[[cms::thread_safe]] static std::set<std::string> squelchSet;
CMS_THREAD_SAFE static std::shared_ptr<edm::service::AbstractMLscribe> mlscribe_ptr;
CMS_THREAD_SAFE static edm::ELseverityLevel threshold;
CMS_THREAD_SAFE static std::set<std::string> squelchSet;

}; // MessageLoggerQ

Expand Down
3 changes: 2 additions & 1 deletion FWCore/MessageLogger/src/ErrorObj.cc
Expand Up @@ -42,6 +42,7 @@
#include <atomic>

#include "FWCore/MessageLogger/interface/ErrorObj.h"
#include "FWCore/Utilities/interface/thread_safety_macros.h"

#ifndef IOSTREAM_INCLUDED
#endif
Expand Down Expand Up @@ -69,7 +70,7 @@ namespace edm

// --- class-wide serial number stamper:
//
[[cms::thread_safe]] static std::atomic<int> ourSerial( 0 );
CMS_THREAD_SAFE static std::atomic<int> ourSerial( 0 );
const unsigned int maxIDlength( 200 ); // changed 4/28/06 from 20


Expand Down
7 changes: 4 additions & 3 deletions FWCore/MessageLogger/src/MessageLoggerQ.cc
@@ -1,7 +1,8 @@
#include "FWCore/MessageLogger/interface/MessageLoggerQ.h"
#include "FWCore/MessageLogger/interface/AbstractMLscribe.h"
#include "FWCore/Utilities/interface/EDMException.h"
#include "FWCore/MessageLogger/interface/ErrorObj.h"
#include "FWCore/MessageLogger/interface/MessageLoggerQ.h"
#include "FWCore/Utilities/interface/EDMException.h"
#include "FWCore/Utilities/interface/thread_safety_macros.h"

#include <cstring>
#include <iostream>
Expand Down Expand Up @@ -130,7 +131,7 @@ MessageLoggerQ::~MessageLoggerQ()
MessageLoggerQ *
MessageLoggerQ::instance()
{
[[cms::thread_safe]] static MessageLoggerQ queue;
CMS_THREAD_SAFE static MessageLoggerQ queue;
return &queue;
} // MessageLoggerQ::instance()

Expand Down
8 changes: 4 additions & 4 deletions FWCore/MessageLogger/src/MessageSender.cc
@@ -1,8 +1,8 @@
#include "FWCore/MessageLogger/interface/ErrorSummaryEntry.h"
#include "FWCore/MessageLogger/interface/MessageSender.h"
#include "FWCore/MessageLogger/interface/MessageLoggerQ.h"
#include "FWCore/MessageLogger/interface/MessageDrop.h"

#include "FWCore/MessageLogger/interface/ErrorSummaryEntry.h"
#include "FWCore/Utilities/interface/thread_safety_macros.h"

#include <algorithm>
#include <cassert>
Expand Down Expand Up @@ -80,9 +80,9 @@ namespace {

}

[[cms::thread_safe]] static std::atomic<bool> errorSummaryIsBeingKept{false};
CMS_THREAD_SAFE static std::atomic<bool> errorSummaryIsBeingKept{false};
//Each item in the vector is reserved for a different Stream
[[cms::thread_safe]] static std::vector<tbb::concurrent_unordered_map<ErrorSummaryMapKey, AtomicUnsignedInt,ErrorSummaryMapKey::key_hash>> errorSummaryMaps;
CMS_THREAD_SAFE static std::vector<tbb::concurrent_unordered_map<ErrorSummaryMapKey, AtomicUnsignedInt,ErrorSummaryMapKey::key_hash>> errorSummaryMaps;

MessageSender::MessageSender( ELseverityLevel const & sev,
ELstring const & id,
Expand Down
6 changes: 3 additions & 3 deletions FWCore/MessageService/interface/ELstatistics.h
Expand Up @@ -26,11 +26,11 @@
//
// ----------------------------------------------------------------------

#include "FWCore/MessageService/interface/ELdestination.h"

#include "FWCore/MessageLogger/interface/ELextendedID.h"
#include "FWCore/MessageLogger/interface/ELmap.h"
#include "FWCore/MessageLogger/interface/ELstring.h"
#include "FWCore/MessageService/interface/ELdestination.h"
#include "FWCore/Utilities/interface/thread_safety_macros.h"

#include <set>

Expand Down Expand Up @@ -107,7 +107,7 @@ class ELstatistics : public ELdestination {

bool printAtTermination;

[[cms::thread_safe]] static std::set<std::string> groupedCategories; // 8/16/07 mf
CMS_THREAD_SAFE static std::set<std::string> groupedCategories; // 8/16/07 mf
static ELstring formSummary(ELmap_stats & stats); // 8/16/07 mf

// ---- Helper methods specific to MessageLogger applicaton
Expand Down
12 changes: 6 additions & 6 deletions FWCore/MessageService/interface/MessageLogger.h
Expand Up @@ -31,11 +31,11 @@

// user include files

#include "FWCore/MessageLogger/interface/ErrorObj.h"

#include "FWCore/ServiceRegistry/interface/ActivityRegistry.h"
#include "DataFormats/Provenance/interface/EventID.h"
#include "FWCore/MessageLogger/interface/ELseverityLevel.h"
#include "FWCore/MessageLogger/interface/ErrorObj.h"
#include "FWCore/ServiceRegistry/interface/ActivityRegistry.h"
#include "FWCore/Utilities/interface/thread_safety_macros.h"

// forward declarations

Expand Down Expand Up @@ -160,10 +160,10 @@ class MessageLogger {
std::set<std::string> debugEnabledModules_;
std::map<std::string,ELseverityLevel> suppression_levels_;
bool debugEnabled_;
[[cms::thread_safe]] static bool anyDebugEnabled_;
[[cms::thread_safe]] static bool everyDebugEnabled_;
CMS_THREAD_SAFE static bool anyDebugEnabled_;
CMS_THREAD_SAFE static bool everyDebugEnabled_;

[[cms::thread_safe]] static bool fjrSummaryRequested_;
CMS_THREAD_SAFE static bool fjrSummaryRequested_;
bool messageServicePSetHasBeenValidated_;
std::string messageServicePSetValidatationResults_;

Expand Down
3 changes: 2 additions & 1 deletion FWCore/ParameterSet/src/Registry.cc
Expand Up @@ -4,13 +4,14 @@
#include <ostream>

#include "FWCore/ParameterSet/interface/Registry.h"
#include "FWCore/Utilities/interface/thread_safety_macros.h"

namespace edm {
namespace pset {

Registry*
Registry::instance() {
[[cms::thread_safe]] static Registry s_reg;
CMS_THREAD_SAFE static Registry s_reg;
return &s_reg;
}

Expand Down
3 changes: 2 additions & 1 deletion FWCore/PluginManager/interface/PluginFactory.h
Expand Up @@ -25,6 +25,7 @@
// user include files
#include "FWCore/PluginManager/interface/PluginFactoryBase.h"
#include "FWCore/PluginManager/interface/PluginManager.h"
#include "FWCore/Utilities/interface/thread_safety_macros.h"
// forward declarations

namespace edmplugin {
Expand Down Expand Up @@ -89,7 +90,7 @@ class PluginFactory<R*(Args...)> : public PluginFactoryBase
#define CONCATENATE(a,b) CONCATENATE_HIDDEN(a,b)
#define EDM_REGISTER_PLUGINFACTORY(_factory_,_category_) \
namespace edmplugin {\
template<> edmplugin::PluginFactory<_factory_::TemplateArgType>* edmplugin::PluginFactory<_factory_::TemplateArgType>::get() { [[cms::thread_safe]] static edmplugin::PluginFactory<_factory_::TemplateArgType> s_instance; return &s_instance;}\
template<> edmplugin::PluginFactory<_factory_::TemplateArgType>* edmplugin::PluginFactory<_factory_::TemplateArgType>::get() { CMS_THREAD_SAFE static edmplugin::PluginFactory<_factory_::TemplateArgType> s_instance; return &s_instance;}\
template<> const std::string& edmplugin::PluginFactory<_factory_::TemplateArgType>::category() const { static const std::string s_cat(_category_); return s_cat;}\
} enum {CONCATENATE(dummy_edm_register_pluginfactory_, __LINE__)}

Expand Down
3 changes: 2 additions & 1 deletion FWCore/PluginManager/src/PluginCapabilities.cc
Expand Up @@ -17,6 +17,7 @@
#include "FWCore/PluginManager/interface/SharedLibrary.h"
#include "FWCore/PluginManager/interface/PluginManager.h"
#include "FWCore/Utilities/interface/Exception.h"
#include "FWCore/Utilities/interface/thread_safety_macros.h"

namespace edmplugin {
//
Expand Down Expand Up @@ -163,7 +164,7 @@ PluginCapabilities::category() const
//
PluginCapabilities*
PluginCapabilities::get() {
[[cms::thread_safe]] static PluginCapabilities s_instance;
CMS_THREAD_SAFE static PluginCapabilities s_instance;
return &s_instance;
}

Expand Down
3 changes: 2 additions & 1 deletion FWCore/PluginManager/src/PluginFactoryManager.cc
Expand Up @@ -14,6 +14,7 @@

// user include files
#include "FWCore/PluginManager/interface/PluginFactoryManager.h"
#include "FWCore/Utilities/interface/thread_safety_macros.h"

namespace edmplugin{
//
Expand Down Expand Up @@ -83,7 +84,7 @@ PluginFactoryManager::end() const
PluginFactoryManager*
PluginFactoryManager::get()
{
[[cms::thread_safe]] static PluginFactoryManager s_instance;
CMS_THREAD_SAFE static PluginFactoryManager s_instance;
return &s_instance;
}
}
12 changes: 6 additions & 6 deletions FWCore/PluginManager/src/PluginManager.cc
Expand Up @@ -22,13 +22,13 @@
#include "TVirtualMutex.h"

// user include files
#include "FWCore/PluginManager/interface/PluginManager.h"
#include "FWCore/PluginManager/interface/CacheParser.h"
#include "FWCore/PluginManager/interface/PluginFactoryBase.h"
#include "FWCore/PluginManager/interface/PluginFactoryManager.h"
#include "FWCore/PluginManager/interface/CacheParser.h"
#include "FWCore/Utilities/interface/Exception.h"

#include "FWCore/PluginManager/interface/PluginManager.h"
#include "FWCore/PluginManager/interface/standard.h"
#include "FWCore/Utilities/interface/Exception.h"
#include "FWCore/Utilities/interface/thread_safety_macros.h"

namespace edmplugin {
//
Expand Down Expand Up @@ -360,13 +360,13 @@ PluginManager::loadingLibraryNamed_()
{
//NOTE: pluginLoadMutex() indirectly guards this since this value
// is only accessible via the Sentry call which us guarded by the mutex
[[cms::thread_safe]] static std::string s_name(staticallyLinkedLoadingFileName());
CMS_THREAD_SAFE static std::string s_name(staticallyLinkedLoadingFileName());
return s_name;
}

PluginManager*& PluginManager::singleton()
{
[[cms::thread_safe]] static PluginManager* s_singleton=nullptr;
CMS_THREAD_SAFE static PluginManager* s_singleton=nullptr;
return s_singleton;
}

Expand Down
3 changes: 2 additions & 1 deletion FWCore/PluginManager/src/PresenceFactory.cc
@@ -1,6 +1,7 @@
#include "FWCore/PluginManager/interface/PresenceFactory.h"
#include "FWCore/Utilities/interface/EDMException.h"
#include "FWCore/Utilities/interface/DebugMacros.h"
#include "FWCore/Utilities/interface/thread_safety_macros.h"

#include <iostream>

Expand All @@ -16,7 +17,7 @@ namespace edm {


PresenceFactory* PresenceFactory::get() {
[[cms::thread_safe]] static PresenceFactory singleInstance_;
CMS_THREAD_SAFE static PresenceFactory singleInstance_;
return &singleInstance_;
}

Expand Down
4 changes: 3 additions & 1 deletion FWCore/Utilities/interface/DebugMacros.h
@@ -1,6 +1,8 @@
#ifndef Utilities_DebugMacros_h
#define Utilities_DebugMacros_h

#include "FWCore/Utilities/interface/thread_safety_macros.h"

namespace edm {
struct debugvalue {

Expand All @@ -12,7 +14,7 @@ namespace edm {
int value_;
};

[[cms::thread_safe]] extern debugvalue debugit;
CMS_THREAD_SAFE extern debugvalue debugit;
}

#define FDEBUG(lev) if(lev <= debugit()) std::cerr
Expand Down
2 changes: 1 addition & 1 deletion FWCore/Utilities/interface/thread_safety_macros.h
@@ -1,6 +1,6 @@
#ifndef FWCore_Utilites_thread_safe_macros_h
#define FWCore_Utilites_thread_safe_macros_h
#ifndef __ROOTCLING__
#if ! defined __ROOTCLING__ && ! defined __INTEL_COMPILER
#define CMS_THREAD_SAFE [[cms::thread_safe]]
#define CMS_THREAD_GUARD(_var_) [[cms::thread_guard("#_var_")]]
#else
Expand Down