| Disk ARchive 2.8.1 Full featured and portable backup and archiving tool

Loading...
Searching...
No Matches
thread_cancellation.hpp
Go to the documentation of this file.
1/*********************************************************************/
2// dar - disk archive - a backup/restoration program
3// Copyright (C) 2002-2025 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
41extern "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
54namespace libdar
55{
56
59
61
67
68 class thread_cancellation
69 {
70 public:
71
73 thread_cancellation();
74
76 thread_cancellation(const thread_cancellation & ref) = default;
77
79 thread_cancellation(thread_cancellation && ref) noexcept = default;
80
82 thread_cancellation & operator = (const thread_cancellation & ref) = default;
83
85 thread_cancellation & operator = (thread_cancellation && ref) noexcept = default;
86
88 virtual ~thread_cancellation() noexcept(false);
89
91
94 void check_self_cancellation() const;
95
97
102 bool self_is_under_cancellation() const;
103
106
110 void block_delayed_cancellation(bool mode);
111
112
113#if MUTEX_WORKS
115
119 static void cancel(pthread_t tid, bool x_immediate, U_64 x_flag);
120
122
125 static bool cancel_status(pthread_t tid);
126
128
131 static bool clear_pending_request(pthread_t tid);
132
141 static void associate_tid_to_tid(pthread_t src, pthread_t dst);
142
147 static void remove_association_for_tid(pthread_t src);
148
152 static void remove_association_targeted_at(pthread_t dst);
153
155 static void dead_thread(pthread_t tid);
156#endif
157
159 static U_I count()
160 {
161#if MUTEX_WORKS
162 return info.size();
163#else
164 return 0;
165#endif
166 };
167
168#if MUTEX_WORKS
169 private:
170
171 // class types
172
173 struct fields
174 {
175 pthread_t tid;
176 bool block_delayed;
177 bool immediate;
178 bool cancellation;
179 bool thrown;
180 U_64 flag;
181 };
182
183 // object information
184
185 fields status;
186
187 // class's static variables and types
188
189 static pthread_mutex_t access;
190 static std::list<thread_cancellation *> info;
191 static std::list<fields> preborn;
192 static std::multimap<pthread_t, pthread_t> thread_asso;
193
194 // helper class routing
195 static void set_cancellation_in_info_for(pthread_t tid,
196 bool cancel_status,
197 bool x_immediate,
198 bool thrown,
199 U_64 x_flag,
200 bool & found,
201 bool & previous_val,
202 bool & bug);
203 static void add_to_preborn(pthread_t tid, bool x_immediate, U_64 x_flag);
204 static void remove_from_preborn(pthread_t tid, bool & found, bool & prev);
205 static void find_asso_tid_with(pthread_t tid,
206 std::multimap<pthread_t, pthread_t>::iterator & begin,
207 std::multimap<pthread_t, pthread_t>::iterator & end);
208
210 static bool flag_exception_thrown(pthread_t tid, bool & found);
211
212#endif
213 };
214
216
217} // end of namespace
218
219#endif
libdar::thread_cancellation
class to be used as parent to provide checkpoints to inherited classes
Definition thread_cancellation.hpp:69
libdar::thread_cancellation::count
static U_I count()
method for debugging/control purposes
Definition thread_cancellation.hpp:159
libdar::thread_cancellation::thread_cancellation
thread_cancellation(thread_cancellation &&ref) noexcept=default
move constructor
libdar::thread_cancellation::~thread_cancellation
virtual ~thread_cancellation() noexcept(false)
the destructor
libdar::thread_cancellation::thread_cancellation
thread_cancellation(const thread_cancellation &ref)=default
copy constructor
libdar::thread_cancellation::block_delayed_cancellation
void block_delayed_cancellation(bool mode)
libdar::thread_cancellation::operator=
thread_cancellation & operator=(const thread_cancellation &ref)=default
assignment operator
libdar::thread_cancellation::thread_cancellation
thread_cancellation()
the constructor
libdar::thread_cancellation::check_self_cancellation
void check_self_cancellation() const
Checkpoint test : whether the current libdar call must abort or not.
libdar::thread_cancellation::self_is_under_cancellation
bool self_is_under_cancellation() const
get the current thread status
erreurs.hpp
contains all the excetion class thrown by libdar
integers.hpp
are defined here basic integer types that tend to be portable
my_config.h
include macro defined by the configure script and some specific additional ones
libdar
libdar namespace encapsulate all libdar symbols
Definition archive.hpp:47