CMS 3D CMS Logo

connect_but_block_self.h
Go to the documentation of this file.
1 #ifndef ServiceRegistry_connect_but_block_self_h
2 #define ServiceRegistry_connect_but_block_self_h
3 // -*- C++ -*-
4 //
5 // Package: ServiceRegistry
6 // Class : connect_but_block_self
7 //
17 //
18 // Original Author: Chris Jones
19 // Created: Thu Sep 22 20:42:32 CEST 2005
20 //
21 
22 // system include files
23 #include <memory>
25 
26 // user include files
27 
28 // forward declarations
29 namespace edm {
30  namespace serviceregistry {
31  template <typename Func>
33  public:
34  BlockingWrapper(Func iFunc) : func_(iFunc), numBlocks_(0) {}
35  //virtual ~BlockingWrapper();
36 
37  // ---------- const member functions ---------------------
38  template <typename... Args>
39  void operator()(Args&&... args) {
40  std::shared_ptr<void> guard(static_cast<void*>(nullptr), std::bind(&BlockingWrapper::unblock, this));
41  if (startBlocking()) {
42  func_(std::forward<Args>(args)...);
43  }
44  }
45 
46  // ---------- static member functions --------------------
47 
48  // ---------- member functions ---------------------------
49 
50  private:
51  // ---------- member data --------------------------------
52  bool startBlocking() { return 1 == ++numBlocks_; }
53  void unblock() { --numBlocks_; }
54  Func func_;
56  };
57 
58  template <class Func, class Signal>
59  void connect_but_block_self(Signal& oSignal, const Func& iFunc) {
60  oSignal.connect(BlockingWrapper<Func>(iFunc));
61  }
62  } // namespace serviceregistry
63 } // namespace edm
64 
65 #endif
HLT enums.
void connect_but_block_self(Signal &oSignal, const Func &iFunc)
Definition: vlib.h:39