Disk ARchive  2.4.5
 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 // $Id$
00022 //
00023 /*********************************************************************/
00024 
00037 
00038 #ifndef THREAD_CANCELLATION_HPP
00039 #define THREAD_CANCELLATION_HPP
00040 
00041 #include "../my_config.h"
00042 
00043 extern "C"
00044 {
00045 #if MUTEX_WORKS
00046 #if HAVE_PTHREAD_H
00047 #include <pthread.h>
00048 #endif
00049 #endif
00050 }
00051 #include <list>
00052 #include "integers.hpp"
00053 
00054 namespace libdar
00055 {
00056 
00058 
00065 
00066     class thread_cancellation
00067     {
00068     public:
00069 
00071         thread_cancellation();
00072 
00074         virtual ~thread_cancellation();
00075 
00077 
00080         void check_self_cancellation() const;
00081 
00084 
00088         void block_delayed_cancellation(bool mode);
00089 
00090 
00092 
00094         static void init();
00095 
00096 
00097 #if MUTEX_WORKS
00098 
00099 
00104         static void cancel(pthread_t tid, bool x_immediate, U_64 x_flag);
00105 
00107 
00110         static bool cancel_status(pthread_t tid);
00111 
00113 
00116         static bool clear_pending_request(pthread_t tid);
00117 #endif
00118 
00120         static U_I count()
00121         {
00122 #if MUTEX_WORKS
00123             return info.size();
00124 #else
00125             return 0;
00126 #endif
00127         };
00128 
00129 #if MUTEX_WORKS
00130     private:
00131 
00132             // class types
00133 
00134         struct fields
00135         {
00136             pthread_t tid;             
00137             bool block_delayed;        
00138             bool immediate;            
00139             bool cancellation;         
00140             U_64 flag;                 
00141         };
00142 
00143             // object information
00144 
00145         fields status;
00146 
00147             // class's static variables and types
00148 
00149         static pthread_mutex_t access;                 
00150         static bool initialized;                       
00151         static std::list<thread_cancellation *> info;  
00152         static std::list<fields> preborn;              
00153 
00154 #endif
00155     };
00156 
00157 } // end of namespace
00158 
00159 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines