CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Friends
edm::SharedResourcesRegistry Class Reference

#include <SharedResourcesRegistry.h>

Public Member Functions

SharedResourcesAcquirer createAcquirer (std::vector< std::string > const &) const
 
std::pair< SharedResourcesAcquirer, std::shared_ptr< std::recursive_mutex > > createAcquirerForSourceDelayedReader ()
 
const SharedResourcesRegistryoperator= (const SharedResourcesRegistry &)=delete
 
void registerSharedResource (const std::string &)
 A resource name must be registered before it can be used in the createAcquirer call. More...
 
 SharedResourcesRegistry (const SharedResourcesRegistry &)=delete
 

Static Public Member Functions

static SharedResourcesRegistryinstance ()
 

Private Member Functions

 SharedResourcesRegistry ()
 
 ~SharedResourcesRegistry ()=default
 

Private Attributes

edm::propagate_const< std::shared_ptr< SerialTaskQueue > > queueForDelayedReader_
 
edm::propagate_const< std::shared_ptr< std::recursive_mutex > > resourceForDelayedReader_
 
std::map< std::string, std::pair< std::shared_ptr< SerialTaskQueue >, unsigned int > > resourceMap_
 

Friends

class ::testSharedResourcesRegistry
 

Detailed Description

Definition at line 35 of file SharedResourcesRegistry.h.

Constructor & Destructor Documentation

◆ SharedResourcesRegistry() [1/2]

edm::SharedResourcesRegistry::SharedResourcesRegistry ( const SharedResourcesRegistry )
delete

◆ SharedResourcesRegistry() [2/2]

SharedResourcesRegistry::SharedResourcesRegistry ( )
private

Definition at line 26 of file SharedResourcesRegistry.cc.

26 {}

◆ ~SharedResourcesRegistry()

edm::SharedResourcesRegistry::~SharedResourcesRegistry ( )
privatedefault

Member Function Documentation

◆ createAcquirer()

SharedResourcesAcquirer SharedResourcesRegistry::createAcquirer ( std::vector< std::string > const &  resourceNames) const

Definition at line 53 of file SharedResourcesRegistry.cc.

References cms::cuda::assert(), eostools::move(), Skims_PA_cff::name, nnet::resource, and resourceMap_.

Referenced by edm::one::impl::SharedResourcesUser< T >::createAcquirer().

53  {
54  // The acquirer will acquire the shared resources declared by a module
55  // so that only it can use those resources while it runs. The other
56  // modules using the same resource will not be run until the module
57  // that acquired the resources completes its task.
58 
59  // Sort by how often used and then by name
60  // Consistent sorting avoids deadlocks and this particular order optimizes performance
61  std::map<std::pair<unsigned int, std::string>, std::shared_ptr<SerialTaskQueue>> sortedResources;
62 
63  for (auto const& name : resourceNames) {
64  auto resource = resourceMap_.find(name);
65  assert(resource != resourceMap_.end());
66  // If only one module wants it, it really isn't shared
67  if (resource->second.second > 1) {
68  sortedResources.insert(
69  std::make_pair(std::make_pair(resource->second.second, resource->first), resource->second.first));
70  }
71  }
72 
73  std::vector<std::shared_ptr<SerialTaskQueue>> queues;
74  queues.reserve(sortedResources.size());
75  for (auto const& resource : sortedResources) {
76  queues.push_back(resource.second);
77  }
78  if (queues.empty()) {
79  //Calling code is depending on there being at least one shared queue
80  queues.reserve(1);
81  queues.push_back(std::make_shared<SerialTaskQueue>());
82  }
83 
84  return SharedResourcesAcquirer(std::move(queues));
85  }
assert(be >=bs)
std::map< std::string, std::pair< std::shared_ptr< SerialTaskQueue >, unsigned int > > resourceMap_
def move(src, dest)
Definition: eostools.py:511

◆ createAcquirerForSourceDelayedReader()

std::pair< SharedResourcesAcquirer, std::shared_ptr< std::recursive_mutex > > SharedResourcesRegistry::createAcquirerForSourceDelayedReader ( )

Definition at line 42 of file SharedResourcesRegistry.cc.

References edm::get_underlying(), eostools::move(), queueForDelayedReader_, and resourceForDelayedReader_.

Referenced by edm::DelayedReaderThrowingSource::DelayedReaderThrowingSource(), edm::PoolSource::PoolSource(), and edm::RootDelayedReader::RootDelayedReader().

42  {
43  if (not resourceForDelayedReader_) {
45  std::make_shared<std::recursive_mutex>(); // propagate_const<T> has no reset() function
46  queueForDelayedReader_ = std::make_shared<SerialTaskQueue>();
47  }
48 
49  std::vector<std::shared_ptr<SerialTaskQueue>> queues = {get_underlying(queueForDelayedReader_)};
51  }
edm::propagate_const< std::shared_ptr< SerialTaskQueue > > queueForDelayedReader_
edm::propagate_const< std::shared_ptr< std::recursive_mutex > > resourceForDelayedReader_
constexpr T & get_underlying(propagate_const< T > &)
def move(src, dest)
Definition: eostools.py:511

◆ instance()

SharedResourcesRegistry * SharedResourcesRegistry::instance ( )
static

◆ operator=()

const SharedResourcesRegistry& edm::SharedResourcesRegistry::operator= ( const SharedResourcesRegistry )
delete

◆ registerSharedResource()

void SharedResourcesRegistry::registerSharedResource ( const std::string &  resourceName)

A resource name must be registered before it can be used in the createAcquirer call.

Definition at line 28 of file SharedResourcesRegistry.cc.

References resourceMap_.

Referenced by edm::one::impl::SharedResourcesUser< T >::usesResource().

28  {
29  auto& queueAndCounter = resourceMap_[resourceName];
30 
31  // count the number of times the resource was registered
32  ++queueAndCounter.second;
33 
34  // If registering a resource the second time
35  // we know we will need the queue so go ahead and create it.
36  if (queueAndCounter.second == 2) {
37  queueAndCounter.first = std::make_shared<SerialTaskQueue>();
38  }
39  }
std::map< std::string, std::pair< std::shared_ptr< SerialTaskQueue >, unsigned int > > resourceMap_

Friends And Related Function Documentation

◆ ::testSharedResourcesRegistry

friend class ::testSharedResourcesRegistry
friend

Definition at line 38 of file SharedResourcesRegistry.h.

Member Data Documentation

◆ queueForDelayedReader_

edm::propagate_const<std::shared_ptr<SerialTaskQueue> > edm::SharedResourcesRegistry::queueForDelayedReader_
private

Definition at line 68 of file SharedResourcesRegistry.h.

Referenced by createAcquirerForSourceDelayedReader().

◆ resourceForDelayedReader_

edm::propagate_const<std::shared_ptr<std::recursive_mutex> > edm::SharedResourcesRegistry::resourceForDelayedReader_
private

Definition at line 66 of file SharedResourcesRegistry.h.

Referenced by createAcquirerForSourceDelayedReader().

◆ resourceMap_

std::map<std::string, std::pair<std::shared_ptr<SerialTaskQueue>, unsigned int> > edm::SharedResourcesRegistry::resourceMap_
private

Definition at line 64 of file SharedResourcesRegistry.h.

Referenced by createAcquirer(), and registerSharedResource().