Disk ARchive  2.4.12
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
thread_cancellation.hpp
Go to the documentation of this file.
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 : http://dar.linux.free.fr/email.html
00020 /*********************************************************************/
00021 
00034 
00035 #ifndef THREAD_CANCELLATION_HPP
00036 #define THREAD_CANCELLATION_HPP
00037 
00038 #include "../my_config.h"
00039 
00040 extern "C"
00041 {
00042 #if MUTEX_WORKS
00043 #if HAVE_PTHREAD_H
00044 #include <pthread.h>
00045 #endif
00046 #endif
00047 }
00048 #include <list>
00049 #include "integers.hpp"
00050 
00051 namespace libdar
00052 {
00053 
00055 
00062 
00063     class thread_cancellation
00064     {
00065     public:
00066 
00068         thread_cancellation();
00069 
00071         virtual ~thread_cancellation();
00072 
00074 
00077         void check_self_cancellation() const;
00078 
00081 
00085         void block_delayed_cancellation(bool mode);
00086 
00087 
00089 
00091         static void init();
00092 
00093 
00094 #if MUTEX_WORKS
00095 
00096 
00101         static void cancel(pthread_t tid, bool x_immediate, U_64 x_flag);
00102 
00104 
00107         static bool cancel_status(pthread_t tid);
00108 
00110 
00113         static bool clear_pending_request(pthread_t tid);
00114 #endif
00115 
00117         static U_I count()
00118         {
00119 #if MUTEX_WORKS
00120             return info.size();
00121 #else
00122             return 0;
00123 #endif
00124         };
00125 
00126 #if MUTEX_WORKS
00127     private:
00128 
00129             // class types
00130 
00131         struct fields
00132         {
00133             pthread_t tid;             
00134             bool block_delayed;        
00135             bool immediate;            
00136             bool cancellation;         
00137             U_64 flag;                 
00138         };
00139 
00140             // object information
00141 
00142         fields status;
00143 
00144             // class's static variables and types
00145 
00146         static pthread_mutex_t access;                 
00147         static bool initialized;                       
00148         static std::list<thread_cancellation *> info;  
00149         static std::list<fields> preborn;              
00150 
00151 #endif
00152     };
00153 
00154 } // end of namespace
00155 
00156 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines