thread_cancellation.hpp
Go to the documentation of this file.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 #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
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
00143
00144 fields status;
00145
00146
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 }
00157
00158 #endif