Subordination
A framework for distributed programming
kernel_base.hh
1 #ifndef SUBORDINATION_KERNEL_KERNEL_BASE_HH
2 #define SUBORDINATION_KERNEL_KERNEL_BASE_HH
3 
4 #include <bitset>
5 #include <cassert>
6 #include <chrono>
7 
8 #ifndef NDEBUG
9 #include <unistdx/util/backtrace>
10 #endif
11 
12 #include <subordination/kernel/exit_code.hh>
13 #include <subordination/kernel/kernel_flag.hh>
14 
15 namespace sbn {
16 
17  class kernel_base {
18 
19  public:
21  typedef clock_type::time_point time_point;
22  typedef clock_type::duration duration;
23  typedef std::bitset<6> flags_type;
24 
25  protected:
26  exit_code _result = exit_code::undefined;
27  time_point _at = time_point(duration::zero());
28  flags_type _flags = 0;
29 
30  public:
31  virtual
32  ~kernel_base() {
33  #ifndef NDEBUG
34  if (this->isset(kernel_flag::deleted)) {
35  sys::backtrace(2);
36  }
37  assert(!this->isset(kernel_flag::deleted));
38  #endif
39  this->setf(kernel_flag::deleted);
40  }
41 
42  inline exit_code
43  return_code() const noexcept {
44  return _result;
45  }
46 
47  inline void
48  return_code(exit_code rhs) noexcept {
49  this->_result = rhs;
50  }
51 
52  // scheduled kernels
53  inline time_point
54  at() const noexcept {
55  return this->_at;
56  }
57 
58  inline void
59  at(time_point t) noexcept {
60  this->_at = t;
61  }
62 
63  inline void
64  after(duration delay) noexcept {
65  this->_at = clock_type::now() + delay;
66  }
67 
68  inline bool
69  scheduled() const noexcept {
70  return this->_at != time_point(duration::zero());
71  }
72 
73  // flags
74  inline flags_type
75  flags() const noexcept {
76  return this->_flags;
77  }
78 
79  inline void
80  setf(kernel_flag f) noexcept {
81  this->_flags.set(static_cast<size_t>(f));
82  }
83 
84  inline void
85  unsetf(kernel_flag f) noexcept {
86  this->_flags.reset(static_cast<size_t>(f));
87  }
88 
89  inline bool
90  isset(kernel_flag f) const noexcept {
91  return this->_flags.test(static_cast<size_t>(f));
92  }
93 
94  inline bool
95  carries_parent() const noexcept {
96  return this->isset(kernel_flag::carries_parent);
97  }
98 
99  };
100 
101 }
102 
103 #endif // vim:filetype=cpp
Definition: kernel_base.hh:17
T test(T... args)
T reset(T... args)
T set(T... args)