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 : dar.linux@free.fr
00020 /*********************************************************************/
00021 // $Id: thread_cancellation.hpp,v 1.5.2.1 2006/02/04 14:47:15 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 #else
00049 #define pthread_t U_I
00050 #endif
00051 }
00052 #include <list>
00053 #include "integers.hpp"
00054 
00055 namespace libdar
00056 {
00057 
00059 
00066 
00067     class thread_cancellation
00068     {
00069     public:
00070 
00072         thread_cancellation();
00073 
00075         virtual ~thread_cancellation();
00076 
00078 
00081         void check_self_cancellation() const;
00082 
00085 
00089         void block_delayed_cancellation(bool mode);
00090 
00091 
00093 
00095         static void init();
00096 
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 
00118         static U_I count()
00119         {
00120 #if MUTEX_WORKS
00121             return info.size();
00122 #else
00123             return 0;
00124 #endif
00125         };
00126 
00127 #if MUTEX_WORKS
00128     private:
00129 
00130             // class types
00131 
00132         struct fields
00133         {
00134             pthread_t tid;             
00135             bool block_delayed;        
00136             bool immediate;            
00137             bool cancellation;         
00138             U_64 flag;                 
00139         };
00140 
00141             // object information
00142 
00143         fields status;
00144 
00145             // class's static variables and types
00146 
00147         static pthread_mutex_t access;         
00148         static bool initialized;               
00149         static std::list<thread_cancellation *> info;  
00150         static std::list<fields> preborn;      
00151 
00152 #endif
00153     };
00154 
00155 } // end of namespace
00156 
00157 #endif

Generated on Fri Jul 21 19:31:20 2006 for Disk ARchive by  doxygen 1.4.7