00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
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
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
00142
00143 fields status;
00144
00145
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 }
00156
00157 #endif