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

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

thread_cancellation.hpp
Go to the documentation of this file.
1 /*********************************************************************/
2 // dar - disk archive - a backup/restoration program
3 // Copyright (C) 2002-2052 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 //
19 // to contact the author : http://dar.linux.free.fr/email.html
20 /*********************************************************************/
21
34
35 #ifndef THREAD_CANCELLATION_HPP
36 #define THREAD_CANCELLATION_HPP
37
38 #include "../my_config.h"
39
40 extern "C"
41 {
42 #if MUTEX_WORKS
43 #if HAVE_PTHREAD_H
44 #include <pthread.h>
45 #endif
46 #endif
47 }
48 #include <list>
49 #include <map>
50 #include "integers.hpp"
51
52 namespace libdar
53 {
54
56
63
64 class thread_cancellation
65 {
66 public:
67
69 thread_cancellation();
70
72 virtual ~thread_cancellation() throw(Ebug);
73
75
78 void check_self_cancellation() const;
79
82
86 void block_delayed_cancellation(bool mode);
87
88
89 #if MUTEX_WORKS
90
96 static void cancel(pthread_t tid, bool x_immediate, U_64 x_flag);
97
99
102 static bool cancel_status(pthread_t tid);
103
105
108 static bool clear_pending_request(pthread_t tid);
109
118 static void associate_tid_to_tid(pthread_t src, pthread_t dst);
119
124 static void remove_association_for_tid(pthread_t src);
125
129 static void remove_association_targeted_at(pthread_t dst);
130
132 static void dead_thread(pthread_t tid);
133 #endif
134
136 static U_I count()
137 {
138 #if MUTEX_WORKS
139 return info.size();
140 #else
141 return 0;
142 #endif
143 };
144
145 #if MUTEX_WORKS
146 private:
147
148 // class types
149
150 struct fields
151 {
152 pthread_t tid;
153 bool block_delayed;
154 bool immediate;
155 bool cancellation;
156 U_64 flag;
157 };
158
159 // object information
160
161 fields status;
162
163 // class's static variables and types
164
165 static pthread_mutex_t access; //< mutex for the access to "info"
166 static std::list<thread_cancellation *> info; //< list of all object
167 static std::list<fields> preborn; //< canceled thread that still not have a thread_cancellation object to deal with cancellation
168 static std::multimap<pthread_t, pthread_t> thread_asso; //< which other thread to propagate cancellation request to, given a initial tid
169
170 // helper class routing
171 static void set_cancellation_in_info_for(pthread_t tid,
172 bool cancel_status,
173 bool x_immediate,
174 U_64 x_flag,
175 bool & found,
176 bool & previous_val,
177 bool & bug);
178 static void add_to_preborn(pthread_t tid, bool x_immediate, U_64 x_flag);
179 static void remove_from_preborn(pthread_t tid, bool & found, bool & prev);
180 static void find_asso_tid_with(pthread_t tid,
181 std::multimap<pthread_t, pthread_t>::iterator & begin,
182 std::multimap<pthread_t, pthread_t>::iterator & end);
183
184 #endif
185 };
186
187 } // end of namespace
188
189 #endif
integers.hpp
are defined here basic integer types that tend to be portable
libdar::thread_cancellation::block_delayed_cancellation
void block_delayed_cancellation(bool mode)
libdar::thread_cancellation::count
static U_I count()
method for debugging/control purposes
Definition: thread_cancellation.hpp:136
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::~thread_cancellation
virtual ~thread_cancellation()
the destructor
libdar::thread_cancellation
class to be used as parent to provide checkpoints to inherited classes
Definition: thread_cancellation.hpp:64
libdar::thread_cancellation::thread_cancellation
thread_cancellation()
the constructor
libdar::Ebug
exception used to signal a bug. A bug is triggered when reaching some code that should never be reach...
Definition: erreurs.hpp:137
libdar
libdar namespace encapsulate all libdar symbols
Definition: archive.hpp:47