Disk ARchive  2.4.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
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 // $Id: thread_cancellation.hpp,v 1.15 2011/01/09 17:25:58 edrusb Rel $
22 //
23 /*********************************************************************/
24 
37 
38 #ifndef THREAD_CANCELLATION_HPP
39 #define THREAD_CANCELLATION_HPP
40 
41 #include "../my_config.h"
42 
43 extern "C"
44 {
45 #if MUTEX_WORKS
46 #if HAVE_PTHREAD_H
47 #include <pthread.h>
48 #endif
49 #endif
50 }
51 #include <list>
52 #include "integers.hpp"
53 
54 namespace libdar
55 {
56 
58 
65 
67  {
68  public:
69 
72 
74  virtual ~thread_cancellation();
75 
77 
80  void check_self_cancellation() const;
81 
84 
88  void block_delayed_cancellation(bool mode);
89 
90 
92 
94  static void init();
95 
96 
97 #if MUTEX_WORKS
98 
99 
104  static void cancel(pthread_t tid, bool x_immediate, U_64 x_flag);
105 
107 
110  static bool cancel_status(pthread_t tid);
111 
113 
116  static bool clear_pending_request(pthread_t tid);
117 #endif
118 
120  static U_I count()
121  {
122 #if MUTEX_WORKS
123  return info.size();
124 #else
125  return 0;
126 #endif
127  };
128 
129 #if MUTEX_WORKS
130  private:
131 
132  // class types
133 
134  struct fields
135  {
136  pthread_t tid;
137  bool block_delayed;
138  bool immediate;
139  bool cancellation;
140  U_64 flag;
141  };
142 
143  // object information
144 
145  fields status;
146 
147  // class's static variables and types
148 
149  static pthread_mutex_t access;
150  static bool initialized;
151  static std::list<thread_cancellation *> info;
152  static std::list<fields> preborn;
153 
154 #endif
155  };
156 
157 } // end of namespace
158 
159 #endif