test
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  auto iThis = this;
55  std::shared_ptr<void> guard(nullptr,[iThis](void* ) {iThis->lock();});
56  this->unlock();
57  iFunc();
58  }
59 
61  size_t numberOfResources() const { return m_resources.size();}
62  private:
63 
64  // ---------- member data --------------------------------
65  std::vector<std::recursive_mutex*> m_resources;
66  };
67 }
68 
69 
70 #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)