Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-08-18 22:30:17

0001 #ifndef FWCore_Framework_SharedResourcesRegistry_h
0002 #define FWCore_Framework_SharedResourcesRegistry_h
0003 // -*- C++ -*-
0004 //
0005 // Package:     FWCore/Framework
0006 // Class  :     SharedResourcesRegistry
0007 //
0008 /**\class SharedResourcesRegistry SharedResourcesRegistry.h "SharedResourcesRegistry.h"
0009 
0010  Description: Manages the Acquirers used to take temporary control of a resource shared between modules
0011 
0012  Usage:
0013     <usage>
0014 
0015 */
0016 //
0017 // Original Author:  Chris Jones
0018 //         Created:  Sun, 06 Oct 2013 15:48:44 GMT
0019 //
0020 
0021 // system include files
0022 #include <vector>
0023 #include <string>
0024 #include <map>
0025 #include <mutex>
0026 #include <memory>
0027 
0028 #include "FWCore/Concurrency/interface/SerialTaskQueue.h"
0029 #include "FWCore/Utilities/interface/propagate_const.h"
0030 
0031 // user include files
0032 
0033 // forward declarations
0034 class testSharedResourcesRegistry;
0035 
0036 namespace edm {
0037   class SharedResourcesAcquirer;
0038 
0039   class SharedResourcesRegistry {
0040   public:
0041     //needed for testing
0042     friend class ::testSharedResourcesRegistry;
0043 
0044     SharedResourcesRegistry(const SharedResourcesRegistry&) = delete;                   // stop default
0045     const SharedResourcesRegistry& operator=(const SharedResourcesRegistry&) = delete;  // stop default
0046 
0047     // ---------- const member functions ---------------------
0048     SharedResourcesAcquirer createAcquirer(std::vector<std::string> const&) const;
0049 
0050     std::pair<SharedResourcesAcquirer, std::shared_ptr<std::recursive_mutex>> createAcquirerForSourceDelayedReader();
0051 
0052     // ---------- static member functions --------------------
0053     static SharedResourcesRegistry* instance();
0054 
0055     ///All legacy modules share this resource
0056     static const std::string kLegacyModuleResourceName;
0057 
0058     // ---------- member functions ---------------------------
0059     ///A resource name must be registered before it can be used in the createAcquirer call
0060     void registerSharedResource(const std::string&);
0061 
0062 #ifdef SHAREDRESOURCETESTACCESSORS
0063     // The next function is intended to be used only in a unit test
0064     std::map<std::string, std::pair<std::shared_ptr<SerialTaskQueue>, unsigned int>> const& resourceMap() const {
0065       return resourceMap_;
0066     }
0067 #endif
0068 
0069   private:
0070     SharedResourcesRegistry();
0071     ~SharedResourcesRegistry() = default;
0072 
0073     // ---------- member data --------------------------------
0074     std::map<std::string, std::pair<std::shared_ptr<SerialTaskQueue>, unsigned int>> resourceMap_;
0075 
0076     edm::propagate_const<std::shared_ptr<std::recursive_mutex>> resourceForDelayedReader_;
0077 
0078     edm::propagate_const<std::shared_ptr<SerialTaskQueue>> queueForDelayedReader_;
0079 
0080     unsigned int nLegacy_;
0081   };
0082 }  // namespace edm
0083 
0084 #endif