1 /* Threshold_Watcher and associated classes' declaration and inline functions.
2    Copyright (C) 2001-2010 Roberto Bagnara <bagnara@cs.unipr.it>
3    Copyright (C) 2010-2016 BUGSENG srl (http://bugseng.com)
4 
5 This file is part of the Parma Polyhedra Library (PPL).
6 
7 The PPL is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11 
12 The PPL is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15 for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software Foundation,
19 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA.
20 
21 For the most up-to-date information see the Parma Polyhedra Library
22 site: http://bugseng.com/products/ppl/ . */
23 
24 #ifndef PPL_Threshold_Watcher_defs_hh
25 #define PPL_Threshold_Watcher_defs_hh 1
26 
27 #include "Threshold_Watcher_types.hh"
28 #include "Handler_types.hh"
29 #include "Pending_List_defs.hh"
30 #include <cassert>
31 
32 /*! \brief
33   A class of watchdogs controlling the exceeding of a threshold.
34 
35   \tparam Traits
36   A class to set data types and functions for the threshold handling.
37   See \c Parma_Polyhedra_Library::Weightwatch_Traits for an example.
38 */
39 template <typename Traits>
40 class Parma_Polyhedra_Library::Threshold_Watcher {
41 public:
42   template <typename Flag_Base, typename Flag>
43   Threshold_Watcher(const typename Traits::Delta& delta,
44                     const Flag_Base* volatile& holder,
45                     Flag& flag);
46 
47   Threshold_Watcher(const typename Traits::Delta& delta,
48                     void (*function)());
49 
50   ~Threshold_Watcher();
51 
52 private:
53   typedef Implementation::Watchdog::Pending_List<Traits> TW_Pending_List;
54   typedef Implementation::Watchdog::Handler TW_Handler;
55 
56   bool expired;
57   const TW_Handler& handler;
58   typename TW_Pending_List::iterator pending_position;
59 
60   // Just to prevent their use.
61   Threshold_Watcher(const Threshold_Watcher&);
62   Threshold_Watcher& operator=(const Threshold_Watcher&);
63 
64   struct Initialize {
65     //! The ordered queue of pending thresholds.
66     TW_Pending_List pending;
67   };
68   static Initialize init;
69 
70   // Handle the addition of a new threshold.
71   static typename TW_Pending_List::iterator
72   add_threshold(typename Traits::Threshold threshold,
73                 const TW_Handler& handler,
74                 bool& expired_flag);
75 
76   // Handle the removal of a threshold.
77   static typename TW_Pending_List::iterator
78   remove_threshold(typename TW_Pending_List::iterator position);
79 
80   //! Check threshold reaching.
81   static void check();
82 
83 }; // class Parma_Polyhedra_Library::Threshold_Watcher
84 
85 
86 // Templatic initialization of static data member.
87 template <typename Traits>
88 typename
89 Parma_Polyhedra_Library::Threshold_Watcher<Traits>::Initialize
90 Parma_Polyhedra_Library::Threshold_Watcher<Traits>::init;
91 
92 #include "Threshold_Watcher_inlines.hh"
93 #include "Threshold_Watcher_templates.hh"
94 
95 #endif // !defined(PPL_Threshold_Watcher_defs_hh)
96 
97