Disk ARchive  2.7.14
Full featured and portable backup and archiving tool
thread_cancellation.hpp
Go to the documentation of this file.
1 /*********************************************************************/
2 // dar - disk archive - a backup/restoration program
3 // Copyright (C) 2002-2024 Denis Corbin
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 //
19 // to contact the author, see the AUTHOR file
20 /*********************************************************************/
21 
25 
35 
36 #ifndef THREAD_CANCELLATION_HPP
37 #define THREAD_CANCELLATION_HPP
38 
39 #include "../my_config.h"
40 
41 extern "C"
42 {
43 #if MUTEX_WORKS
44 #if HAVE_PTHREAD_H
45 #include <pthread.h>
46 #endif
47 #endif
48 }
49 #include <list>
50 #include <map>
51 #include "integers.hpp"
52 #include "erreurs.hpp"
53 
54 namespace libdar
55 {
56 
59 
61 
67 
69  {
70  public:
71 
74 
76  thread_cancellation(const thread_cancellation & ref) = default;
77 
79  thread_cancellation(thread_cancellation && ref) noexcept = default;
80 
83 
85  thread_cancellation & operator = (thread_cancellation && ref) noexcept = default;
86 
88  virtual ~thread_cancellation() noexcept(false);
89 
91 
95 
98 
102  void block_delayed_cancellation(bool mode);
103 
104 
105 #if MUTEX_WORKS
107 
112  static void cancel(pthread_t tid, bool x_immediate, U_64 x_flag);
113 
115 
118  static bool cancel_status(pthread_t tid);
119 
121 
124  static bool clear_pending_request(pthread_t tid);
125 
134  static void associate_tid_to_tid(pthread_t src, pthread_t dst);
135 
140  static void remove_association_for_tid(pthread_t src);
141 
145  static void remove_association_targeted_at(pthread_t dst);
146 
148  static void dead_thread(pthread_t tid);
149 #endif
150 
152  static U_I count()
153  {
154 #if MUTEX_WORKS
155  return info.size();
156 #else
157  return 0;
158 #endif
159  };
160 
161 #if MUTEX_WORKS
162  private:
163 
164  // class types
165 
166  struct fields
167  {
168  pthread_t tid;
169  bool block_delayed;
170  bool immediate;
171  bool cancellation;
172  U_64 flag;
173  };
174 
175  // object information
176 
177  fields status;
178 
179  // class's static variables and types
180 
181  static pthread_mutex_t access;
182  static std::list<thread_cancellation *> info;
183  static std::list<fields> preborn;
184  static std::multimap<pthread_t, pthread_t> thread_asso;
185 
186  // helper class routing
187  static void set_cancellation_in_info_for(pthread_t tid,
188  bool cancel_status,
189  bool x_immediate,
190  U_64 x_flag,
191  bool & found,
192  bool & previous_val,
193  bool & bug);
194  static void add_to_preborn(pthread_t tid, bool x_immediate, U_64 x_flag);
195  static void remove_from_preborn(pthread_t tid, bool & found, bool & prev);
196  static void find_asso_tid_with(pthread_t tid,
197  std::multimap<pthread_t, pthread_t>::iterator & begin,
198  std::multimap<pthread_t, pthread_t>::iterator & end);
199 
200 #endif
201  };
202 
204 
205 } // end of namespace
206 
207 #endif
class to be used as parent to provide checkpoints to inherited classes
static U_I count()
method for debugging/control purposes
thread_cancellation(thread_cancellation &&ref) noexcept=default
move constructor
virtual ~thread_cancellation() noexcept(false)
the destructor
thread_cancellation(const thread_cancellation &ref)=default
copy constructor
thread_cancellation & operator=(const thread_cancellation &ref)=default
assignment operator
void block_delayed_cancellation(bool mode)
thread_cancellation()
the constructor
void check_self_cancellation() const
Checkpoint test : whether the current libdar call must abort or not.
contains all the excetion class thrown by libdar
are defined here basic integer types that tend to be portable
libdar namespace encapsulate all libdar symbols
Definition: archive.hpp:47