Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-06-07 02:29:35

0001 #include "FWCore/Concurrency/interface/Async.h"
0002 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0003 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0004 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0005 #include "FWCore/ServiceRegistry/interface/ActivityRegistry.h"
0006 
0007 #include <atomic>
0008 
0009 namespace edm::service {
0010   class AsyncService : public Async {
0011   public:
0012     AsyncService(ParameterSet const& iConfig, ActivityRegistry& iRegistry);
0013 
0014     static void fillDescriptions(ConfigurationDescriptions& descriptions);
0015 
0016   private:
0017     void ensureAllowed() const final;
0018 
0019     std::atomic<bool> allowed_ = true;
0020   };
0021 
0022   AsyncService::AsyncService(ParameterSet const& iConfig, ActivityRegistry& iRegistry) {
0023     iRegistry.watchPreSourceEarlyTermination([this](TerminationOrigin) { allowed_ = false; });
0024     iRegistry.watchPreGlobalEarlyTermination([this](GlobalContext const&, TerminationOrigin) { allowed_ = false; });
0025     iRegistry.watchPreStreamEarlyTermination([this](StreamContext const&, TerminationOrigin) { allowed_ = false; });
0026     iRegistry.watchPostEndJob([this]() { allowed_ = false; });
0027   }
0028 
0029   void AsyncService::fillDescriptions(ConfigurationDescriptions& descriptions) {
0030     ParameterSetDescription desc;
0031     descriptions.addDefault(desc);
0032   }
0033 
0034   void AsyncService::ensureAllowed() const {
0035     if (not allowed_) {
0036       cms::Exception ex("AsyncCallNotAllowed");
0037       ex.addContext("Calling Async::run()");
0038       ex << "Framework is shutting down, further run() calls are not allowed";
0039       throw ex;
0040     }
0041   }
0042 }  // namespace edm::service
0043 
0044 #include "FWCore/ServiceRegistry/interface/ServiceMaker.h"
0045 
0046 using edm::service::AsyncService;
0047 using AsyncMaker = edm::serviceregistry::AllArgsMaker<edm::Async, AsyncService>;
0048 DEFINE_FWK_SERVICE_MAKER(AsyncService, AsyncMaker);