Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:12:06

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 #include <vector>
0022 #include <string>
0023 #include <map>
0024 #include <mutex>
0025 #include <memory>
0026 
0027 #include "FWCore/Concurrency/interface/SerialTaskQueue.h"
0028 #include "FWCore/Utilities/interface/propagate_const.h"
0029 
0030 class testSharedResourcesRegistry;
0031 
0032 namespace edm {
0033   class SharedResourcesAcquirer;
0034 
0035   class SharedResourcesRegistry {
0036   public:
0037     //needed for testing
0038     friend class ::testSharedResourcesRegistry;
0039 
0040     SharedResourcesRegistry(const SharedResourcesRegistry&) = delete;                   // stop default
0041     const SharedResourcesRegistry& operator=(const SharedResourcesRegistry&) = delete;  // stop default
0042 
0043     SharedResourcesAcquirer createAcquirer(std::vector<std::string> const&) const;
0044 
0045     std::pair<SharedResourcesAcquirer, std::shared_ptr<std::recursive_mutex>> createAcquirerForSourceDelayedReader();
0046 
0047     static SharedResourcesRegistry* instance();
0048 
0049     ///A resource name must be registered before it can be used in the createAcquirer call
0050     void registerSharedResource(const std::string&);
0051 
0052 #ifdef SHAREDRESOURCETESTACCESSORS
0053     // The next function is intended to be used only in a unit test
0054     std::map<std::string, std::pair<std::shared_ptr<SerialTaskQueue>, unsigned int>> const& resourceMap() const {
0055       return resourceMap_;
0056     }
0057 #endif
0058 
0059   private:
0060     SharedResourcesRegistry();
0061     ~SharedResourcesRegistry() = default;
0062 
0063     // ---------- member data --------------------------------
0064     std::map<std::string, std::pair<std::shared_ptr<SerialTaskQueue>, unsigned int>> resourceMap_;
0065 
0066     edm::propagate_const<std::shared_ptr<std::recursive_mutex>> resourceForDelayedReader_;
0067 
0068     edm::propagate_const<std::shared_ptr<SerialTaskQueue>> queueForDelayedReader_;
0069   };
0070 }  // namespace edm
0071 
0072 #endif