Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
try to bind worker threads to cores when possible
[simgrid.git] / include / xbt / signal.hpp
1 /* Copyright (c) 2014-2015. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #ifndef SIMGRID_XBT_SIGNAL_HPP
7 #define SIMGRID_XBT_SIGNAL_HPP
8
9 #ifdef SIMGRID_HAVE_LIBSIG
10 #include <sigc++/sigc++.h>
11 #else
12 #include <boost/signals2.hpp>
13 #endif
14
15 namespace simgrid {
16 namespace xbt {
17
18 #ifdef SIMGRID_HAVE_LIBSIG
19
20   // Wraps sigc++ signals with the interface of boost::signals2:
21   template<class T> class signal;
22   template<class R, class... P>
23   class signal<R(P...)> {
24   private:
25     sigc::signal<R, P...> sig_;
26   public:
27     template<class U> XBT_ALWAYS_INLINE
28     void connect(U&& slot)
29     {
30       sig_.connect(std::forward<U>(slot));
31     }
32     template<class Res, class... Args> XBT_ALWAYS_INLINE
33     void connect(Res(*slot)(Args...))
34     {
35       sig_.connect(sigc::ptr_fun(slot));
36     }
37     template<class... Args> XBT_ALWAYS_INLINE
38     R operator()(Args&&... args) const
39     {
40       return sig_.emit(std::forward<Args>(args)...);
41     }
42     void disconnect_all_slots()
43     {
44       sig_.clear();
45     }
46   };
47
48 #else
49
50   template<class T>
51   using signal = ::boost::signals2::signal<T>;
52
53 #endif
54
55 }
56 }
57
58 #endif