Disk ARchive 2.3.11
|
00001 /*********************************************************************/ 00002 // dar - disk archive - a backup/restoration program 00003 // Copyright (C) 2002-2052 Denis Corbin 00004 // 00005 // This program is free software; you can redistribute it and/or 00006 // modify it under the terms of the GNU General Public License 00007 // as published by the Free Software Foundation; either version 2 00008 // of the License, or (at your option) any later version. 00009 // 00010 // This program is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with this program; if not, write to the Free Software 00017 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00018 // 00019 // to contact the author : dar.linux@free.fr 00020 /*********************************************************************/ 00021 // $Id: thread_cancellation.hpp,v 1.5.2.4 2006/12/12 18:25:35 edrusb Rel $ 00022 // 00023 /*********************************************************************/ 00024 00036 00037 #ifndef THREAD_CANCELLATION_HPP 00038 #define THREAD_CANCELLATION_HPP 00039 00040 #include "../my_config.h" 00041 00042 extern "C" 00043 { 00044 #if MUTEX_WORKS 00045 #if HAVE_PTHREAD_H 00046 #include <pthread.h> 00047 #endif 00048 #endif 00049 } 00050 #include <list> 00051 #include "integers.hpp" 00052 00053 namespace libdar 00054 { 00055 00057 00064 00065 class thread_cancellation 00066 { 00067 public: 00068 00070 thread_cancellation(); 00071 00073 virtual ~thread_cancellation(); 00074 00076 00079 void check_self_cancellation() const; 00080 00083 00087 void block_delayed_cancellation(bool mode); 00088 00089 00091 00093 static void init(); 00094 00095 00096 #if MUTEX_WORKS 00097 00098 00103 static void cancel(pthread_t tid, bool x_immediate, U_64 x_flag); 00104 00106 00109 static bool cancel_status(pthread_t tid); 00110 00112 00115 static bool clear_pending_request(pthread_t tid); 00116 #endif 00117 00119 static U_I count() 00120 { 00121 #if MUTEX_WORKS 00122 return info.size(); 00123 #else 00124 return 0; 00125 #endif 00126 }; 00127 00128 #if MUTEX_WORKS 00129 private: 00130 00131 // class types 00132 00133 struct fields 00134 { 00135 pthread_t tid; 00136 bool block_delayed; 00137 bool immediate; 00138 bool cancellation; 00139 U_64 flag; 00140 }; 00141 00142 // object information 00143 00144 fields status; 00145 00146 // class's static variables and types 00147 00148 static pthread_mutex_t access; 00149 static bool initialized; 00150 static std::list<thread_cancellation *> info; 00151 static std::list<fields> preborn; 00152 00153 #endif 00154 }; 00155 00156 } // end of namespace 00157 00158 #endif