SharedResourcesRegistry.h
Go to the documentation of this file.
1 #ifndef art_Utilities_SharedResourcesRegistry_h
2 #define art_Utilities_SharedResourcesRegistry_h
3 // vim: set sw=2 expandtab :
4 
6 #include "hep_concurrency/RecursiveMutex.h"
7 #include "hep_concurrency/tsan.h"
8 
9 #include <atomic>
10 #include <map>
11 #include <memory>
12 #include <string>
13 #include <utility>
14 #include <vector>
15 
16 namespace hep::concurrency {
17  class SerialTaskQueue;
18 }
19 
20 namespace art {
21 
23  private:
25  public:
27  QueueAndCounter(QueueAndCounter const&) = delete;
28  QueueAndCounter(QueueAndCounter&&) = delete;
29  QueueAndCounter& operator=(QueueAndCounter const&) = delete;
30  QueueAndCounter& operator=(QueueAndCounter&&) = delete;
31 
32  std::shared_ptr<hep::concurrency::SerialTaskQueue> queue_;
33  std::atomic<unsigned long> counter_{0ul};
34  };
35 
36  public:
37  static SharedResourcesRegistry* instance(bool shutdown = false);
39 
43  SharedResourcesRegistry& operator=(SharedResourcesRegistry const&) = delete;
44  SharedResourcesRegistry& operator=(SharedResourcesRegistry&&) = delete;
45 
46  bool containsResource(std::string const&) const;
47  void registerSharedResource(detail::SharedResource_t const&) noexcept(
48  false);
49  void registerSharedResource(std::string const&) noexcept(false);
50  void updateSharedResource(std::string const&) noexcept(false);
51  void freeze();
52  std::vector<std::shared_ptr<hep::concurrency::SerialTaskQueue>>
53  createQueues(std::string const& resourceName) const;
54  std::vector<std::shared_ptr<hep::concurrency::SerialTaskQueue>>
55  createQueues(std::vector<std::string> const& resourceNames) const;
56 
57  private:
58  mutable hep::concurrency::RecursiveMutex mutex_{"srr::mutex_"};
59  std::map<std::string, QueueAndCounter> resourceMap_;
60  bool frozen_;
61  unsigned nLegacy_;
62  };
63 } // namespace art
64 
65 #endif /* art_Utilities_SharedResourcesRegistry_h */
66 
67 // Local Variables:
68 // mode: c++
69 // End:
std::map< std::string, QueueAndCounter > resourceMap_
std::string string
Definition: nybbler.cc:12
const std::string instance
STL namespace.
std::shared_ptr< hep::concurrency::SerialTaskQueue > queue_
static detail::SharedResource_t const Legacy