CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SharedResourcesAcquirer.h
Go to the documentation of this file.
1 #ifndef Subsystem_Package_SharedResourcesAcquirer_h
2 #define Subsystem_Package_SharedResourcesAcquirer_h
3 // -*- C++ -*-
4 //
5 // Package: Subsystem/Package
6 // Class : SharedResourcesAcquirer
7 //
16 //
17 // Original Author: Chris Jones
18 // Created: Sun, 06 Oct 2013 19:43:26 GMT
19 //
20 
21 // system include files
22 
23 // user include files
24 #include <vector>
25 #include <mutex>
26 #include <memory>
27 
28 // forward declarations
29 class testSharedResourcesRegistry;
30 namespace edm {
32  {
33  public:
34  friend class ::testSharedResourcesRegistry;
35 
36  SharedResourcesAcquirer() = default;
37  explicit SharedResourcesAcquirer(std::vector<std::recursive_mutex*>&& iResources):
38  m_resources(iResources){}
39 
43 
44  ~SharedResourcesAcquirer() = default;
45 
46  // ---------- member functions ---------------------------
47  void lock();
48  void unlock();
49 
52  template<typename FUNC>
53  void temporaryUnlock(FUNC iFunc) {
54  std::shared_ptr<SharedResourcesAcquirer*> guard(this,[](SharedResourcesAcquirer* iThis) {iThis->lock();});
55  this->unlock();
56  iFunc();
57  }
58 
60  size_t numberOfResources() const { return m_resources.size();}
61  private:
62 
63  // ---------- member data --------------------------------
64  std::vector<std::recursive_mutex*> m_resources;
65  };
66 }
67 
68 
69 #endif
size_t numberOfResources() const
The number returned may be less than the number of resources requested if a resource is only used by ...
std::vector< std::recursive_mutex * > m_resources
SharedResourcesAcquirer & operator=(const SharedResourcesAcquirer &)=default
SharedResourcesAcquirer(std::vector< std::recursive_mutex * > &&iResources)