CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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  {
34 
35  public:
36 
37  BlockingWrapper(Func iFunc): func_(iFunc), numBlocks_(0) {}
38  //virtual ~BlockingWrapper();
39 
40  // ---------- const member functions ---------------------
41  template<typename... Args>
42  void operator()(Args&&... args) {
43  std::shared_ptr<void> guard(static_cast<void*>(0), std::bind(&BlockingWrapper::unblock,this) );
44  if( startBlocking() ) { func_(std::forward<Args>(args)...); }
45  }
46 
47  // ---------- static member functions --------------------
48 
49  // ---------- member functions ---------------------------
50 
51  private:
52  // ---------- member data --------------------------------
53  bool startBlocking() { return 1 == ++numBlocks_; }
54  void unblock() { --numBlocks_;}
55  Func func_;
57  };
58 
59  template<class Func, class Signal>
60  void
61  connect_but_block_self(Signal& oSignal, const Func& iFunc) {
62  oSignal.connect(BlockingWrapper<Func>(iFunc));
63  }
64  }
65 }
66 
67 #endif
void connect_but_block_self(Signal &oSignal, const Func &iFunc)
Definition: vlib.h:39