18 #ifndef LIBCWD_PRIVATE_STRUCT_TSD_H
19 #define LIBCWD_PRIVATE_STRUCT_TSD_H
21 #ifndef LIBCWD_CONFIG_H
24 #ifndef LIBCWD_PRIVATE_ASSERT_H
27 #ifndef LIBCWD_PRIVATE_MUTEX_INSTANCES_H
34 #ifndef LIBCW_LIMITS_H
35 #define LIBCW_LIMITS_H
38 #if LIBCWD_THREAD_SAFE
40 #ifdef LIBCWD_HAVE_PTHREAD
41 #ifndef LIBCW_PTHREAD_H
42 #define LIBCW_PTHREAD_H
58 #if LIBCWD_THREAD_SAFE
60 #define LIBCWD_TSD __libcwd_tsd // Optional `__libcwd_tsd' parameter (foo() or foo(__libcwd_tsd)).
61 #define LIBCWD_COMMA_TSD , LIBCWD_TSD // Idem, but as second or higher parameter.
62 #define LIBCWD_TSD_PARAM ::libcwd::_private_::TSD_st& __libcwd_tsd
64 #define LIBCWD_TSD_PARAM_UNUSED ::libcwd::_private_::TSD_st&
66 #define LIBCWD_COMMA_TSD_PARAM , LIBCWD_TSD_PARAM // Idem, but as second or higher parameter.
67 #define LIBCWD_COMMA_TSD_PARAM_UNUSED , LIBCWD_TSD_PARAM_UNUSED
69 #define LIBCWD_TSD_INSTANCE ::libcwd::_private_::TSD_st::instance()
71 #define LIBCWD_COMMA_TSD_INSTANCE , LIBCWD_TSD_INSTANCE // Idem, but as second or higher parameter.
72 #define LIBCWD_TSD_DECLARATION ::libcwd::_private_::TSD_st& __libcwd_tsd(::libcwd::_private_::TSD_st::instance())
74 #define LIBCWD_DO_TSD(debug_object) (*__libcwd_tsd.do_array[(debug_object).WNS_index])
76 #define LIBCWD_TSD_MEMBER_OFF (__libcwd_tsd.do_off_array[WNS_index])
78 #define LIBCWD_DO_TSD_MEMBER_OFF(debug_object) (__libcwd_tsd.do_off_array[(debug_object).WNS_index])
81 #else // !LIBCWD_THREAD_SAFE
84 #define LIBCWD_COMMA_TSD
85 #define LIBCWD_TSD_PARAM void
86 #define LIBCWD_TSD_PARAM_UNUSED void
87 #define LIBCWD_COMMA_TSD_PARAM
88 #define LIBCWD_COMMA_TSD_PARAM_UNUSED
89 #define LIBCWD_TSD_INSTANCE
90 #define LIBCWD_COMMA_TSD_INSTANCE
91 #define LIBCWD_TSD_DECLARATION
92 #define LIBCWD_DO_TSD(debug_object) ((debug_object).tsd)
93 #define LIBCWD_TSD_MEMBER_OFF (tsd._off)
94 #define LIBCWD_DO_TSD_MEMBER_OFF(debug_object) ((debug_object).tsd._off)
96 #endif // !LIBCWD_THREAD_SAFE
98 #define LIBCWD_DO_TSD_MEMBER(debug_object, m) (LIBCWD_DO_TSD(debug_object).m)
99 #define LIBCWD_TSD_MEMBER(m) LIBCWD_DO_TSD_MEMBER(*this, m)
102 #ifndef LIBCWD_STRUCT_DEBUG_TSD_H
103 #include <libcwd/struct_debug_tsd.h>
105 #if LIBCWD_THREAD_SAFE
106 #ifndef LIBCWD_PRIVATE_THREAD_H
127 namespace _private_ {
129 extern int WST_initializing_TSD;
137 int inside_malloc_or_free;
139 #endif // CWDEBUG_ALLOC
143 #if LIBCWD_THREAD_SAFE
144 threadlist_t::iterator thread_iter;
145 bool thread_iter_valid;
146 thread_ct* target_thread;
148 bool pthread_lock_interface_is_locked;
149 bool list_allocations_on_show_allthreads;
158 bool recursive_fatal;
160 bool recursive_assert;
163 int cancel_explicitely_deferred;
164 int cancel_explicitely_disabled;
165 int inside_critical_area;
166 int cleanup_handler_installed;
167 int internal_debugging_code;
168 mutex_ct* waiting_for_mutex;
169 int waiting_for_lock;
170 int waiting_for_rdlock;
171 int instance_rdlocked[instance_rdlocked_size];
172 pthread_t rdlocked_by1[instance_rdlocked_size];
173 pthread_t rdlocked_by2[instance_rdlocked_size];
174 void const* rdlocked_from1[instance_rdlocked_size];
175 void const* rdlocked_from2[instance_rdlocked_size];
177 #if LIBCWD_THREAD_SAFE
180 int do_off_array[LIBCWD_DO_MAX];
181 debug_tsd_st* do_array[LIBCWD_DO_MAX];
182 void cleanup_routine(
void);
183 int off_cnt_array[LIBCWD_DC_MAX];
185 int tsd_destructor_count;
189 void thread_destructed(
void);
191 #if LIBCWD_THREAD_SAFE
195 static TSD_st& S_create(
int from_free);
196 static pthread_key_t S_tsd_key;
197 static pthread_once_t S_tsd_key_once;
198 static void S_tsd_key_alloc(
void);
199 static void S_cleanup_routine(
void* arg);
202 static TSD_st& instance(
void);
203 static TSD_st& instance_free(
void);
204 static void free_instance(TSD_st&);
205 #endif // LIBCWD_THREAD_SAFE
211 #if !LIBCWD_THREAD_SAFE
215 extern TSD_st __libcwd_tsd;
217 extern bool WST_tsd_key_created;
220 TSD_st& TSD_st::instance(
void)
223 if (!WST_tsd_key_created || !(instance = (TSD_st*)pthread_getspecific(S_tsd_key)))
230 TSD_st& TSD_st::instance_free(
void)
233 if (!WST_tsd_key_created || !(instance = (TSD_st*)pthread_getspecific(S_tsd_key)))
236 instance->inside_free++;
244 #if !LIBCWD_THREAD_SAFE
247 using ::libcwd::_private_::__libcwd_tsd;
250 #endif // LIBCWD_PRIVATE_STRUCT_TSD_H
unsigned short int location_format_t
The type of the argument of location_format.
Definition: private_struct_TSD.h:122