Disk ARchive 2.8.3
Full featured and portable backup and archiving tool
Loading...
Searching...
No Matches
dar64-2.8.3-win64/include/dar/thread_cancellation.hpp
Go to the documentation of this file.
1/*********************************************************************/
2// dar - disk archive - a backup/restoration program
3// Copyright (C) 2002-2026 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 "//include/dar/libdar_my_config.h"
40
41extern "C"
42{
43#if LIBDAR_MUTEX_WORKS
44#if LIBDAR_HAS_PTHREAD_H
45#include <pthread.h>
46#endif
47#endif
48}
49#include <list>
50#include <map>
51#include "//include/dar/integers.hpp"
52#include "//include/dar/erreurs.hpp"
53
54namespace libdar
55{
56
59
61
67
69 {
70 public:
71
74
77
79 thread_cancellation(thread_cancellation && ref) noexcept = default;
80
83
86
88 virtual ~thread_cancellation() noexcept(false);
89
91
95
97
103
106
111
112
113#if LIBDAR_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 LIBDAR_MUTEX_WORKS
162 return info.size();
163#else
164 return 0;
165#endif
166 };
167
168#if LIBDAR_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
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
void block_delayed_cancellation(bool mode)
thread_cancellation & operator=(const thread_cancellation &ref)=default
assignment operator
thread_cancellation()
the constructor
void check_self_cancellation() const
Checkpoint test : whether the current libdar call must abort or not.
bool self_is_under_cancellation() const
get the current thread status
libdar namespace encapsulate all libdar symbols