libjmmcg  release_579_6_g8cffd
A C++ library containing an eclectic mix of useful, advanced components.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
thread_statistics_impl.hpp
Go to the documentation of this file.
1 /******************************************************************************
2 ** Copyright © 2011 by J.M.McGuiness, coder@hussar.me.uk
3 **
4 ** This library is free software; you can redistribute it and/or
5 ** modify it under the terms of the GNU Lesser General Public
6 ** License as published by the Free Software Foundation; either
7 ** version 2.1 of the License, or (at your option) any later version.
8 **
9 ** This library is distributed in the hope that it will be useful,
10 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 ** Lesser General Public License for more details.
13 **
14 ** You should have received a copy of the GNU Lesser General Public
15 ** License along with this library; if not, write to the Free Software
16 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18 
19 namespace jmmcg { namespace LIBJMMCG_VER_NAMESPACE { namespace ppd {
20 
21 template<class Sz>
22 struct no_statistics<Sz>::process_work_type {
23  static void processed() noexcept(true) {}
24  static void processed(work_added_type const) noexcept(true) {}
25  constexpr static work_added_type total() noexcept(true) {return work_added_type();}
26 
27  friend constexpr tostream & __fastcall operator<<(tostream &os, process_work_type const &) noexcept(true) {
28  return os;
29  }
30 };
31 
32 template<class Sz>
33 class basic_statistics<Sz>::process_work_type {
34 public:
35  constexpr process_work_type() noexcept(true)
36  : work() {
37  }
38  void processed() noexcept(true) {
39  ++work;
40  }
41  void processed(work_added_type const wk) noexcept(true) {
42  work+=wk;
43  }
44  work_added_type total() const noexcept(true) {
45  return work;
46  }
47 
48  /**
49  \todo Implement using the advice given in "Standard C++ IOStreams and Locales" by A.Langer & K.Kreft, page 170.
50  */
51  friend tostream & __fastcall operator<<(tostream &os, process_work_type const &p) noexcept(false) {
52  os<<_T("processed=")<<p.work;
53  return os;
54  }
55 
56 private:
57  work_added_type work;
58 };
59 
60 template<class OST>
61 template<class Node>
62 class no_control_flow_graph<OST>::add_cfg_details {
63 public:
64  struct params {
66  typedef Node node_type;
67  typedef cfg_type::node_property_t node_property_t;
68 
69  constexpr params() noexcept(true)=default;
70  explicit constexpr params(node_property_t::value_type const *) noexcept(true) {}
71  constexpr params(node_property_t::value_type const [], params const &) noexcept(true) {}
72  template<class T> constexpr
73  params(T const *, node_property_t::value_type const *) noexcept(true) {}
74  constexpr params(cfg_type &, params const &) noexcept(true) {}
75  template<class T> constexpr
76  params(cfg_type &, T const *, node_property_t::value_type const []) noexcept(true) {}
77  template<class T> constexpr
78  params(cfg_type &, T const *, node_property_t const &) noexcept(true) {}
79  template<class T> constexpr
80  params(cfg_type &, T const *, params const &) noexcept(true) {}
81  };
82 
83  constexpr add_cfg_details(params const &) noexcept(true) {}
84  add_cfg_details(add_cfg_details const &)=delete;
85 
86  static void update_edge(node_property_t::value_type const) noexcept(true) {}
87 
88  constexpr vertex_t vertex() const noexcept(true) {
89  return vertex_t();
90  }
91 };
92 
93 template<class OST>
94 template<class Node>
96 public:
97  struct params {
99  typedef Node node_type;
100  typedef cfg_type::node_property_t node_property_t;
101 
102  cfg_type * const cfg;
103  node_type const * const parent;
104  node_property_t const details;
105 
106  constexpr params() noexcept(true)
107  : cfg(), parent(), details() {
108  }
109  explicit params(node_property_t::value_type const d[]) noexcept(false)
110  : cfg(), parent(), details(d) {
111  }
112  template<class T>
113  params(T const * p, node_property_t::value_type const d[]) noexcept(false)
114  : cfg(), parent(dynamic_cast<node_type const *>(p)), details(d) {
115  assert(parent==nullptr || dynamic_cast<node_type const *>(parent));
116  }
117  params(cfg_type &c, params const &p) noexcept(false)
118  : cfg(&c), parent(p.parent), details(p.details) {
119  assert(parent==nullptr || dynamic_cast<node_type const *>(parent));
120  }
121  params(node_property_t::value_type const d[], params const &p) noexcept(false)
122  : cfg(p.cfg), parent(p.parent), details(d) {
123  assert(parent==nullptr || dynamic_cast<node_type const *>(parent));
124  }
125  template<class T>
126  params(cfg_type &c, T const *p, node_property_t::value_type const d[]) noexcept(false)
127  : cfg(&c), parent(dynamic_cast<node_type const *>(p)), details(d) {
128  assert(parent==nullptr || dynamic_cast<node_type const *>(parent));
129  }
130  template<class T>
131  params(cfg_type &c, T const *p, node_property_t const &d) noexcept(false)
132  : cfg(&c), parent(dynamic_cast<node_type const *>(p)), details(d) {
133  assert(parent==nullptr || dynamic_cast<node_type const *>(parent));
134  }
135  template<class T>
136  params(cfg_type &c, T const *p, params const &par) noexcept(false)
137  : cfg(&c), parent(dynamic_cast<node_type const *>(p)), details(par.details) {
138  assert(parent==nullptr || dynamic_cast<node_type const *>(parent));
139  }
140  };
141 
142  add_cfg_details(params const &p) noexcept(false)
143  : cfg_(p.cfg) {
144  if (cfg_) {
145  const typename atomic_t::write_lock_type lk(cfg_->lock_, atomic_t::lock_traits::infinite_timeout());
146  vertex_=cfg_->add_vertex_nolk(p.details);
147  if (p.parent) {
148  cfg_->add_edge_nolk(p.parent->vertex(), vertex_, '?');
149  } else {
150  cfg_->add_edge_to_root_nolk(vertex_, '?');
151  }
152  }
153  }
155 
156  void update_edge(node_property_t::value_type const e_details) noexcept(false) {
157  if (cfg_) {
158  const typename atomic_t::write_lock_type lk(cfg_->lock_, atomic_t::lock_traits::infinite_timeout());
159  cfg_->update_edge_nolk(vertex_, e_details);
160  }
161  }
162 
163  vertex_t const &vertex() const noexcept(true) {
164  return vertex_;
165  }
166 
167 private:
168  control_flow_graph * const cfg_;
169  vertex_t vertex_;
170 };
171 
172 } } }