r1007: Make configure detect and work on amd64.
[cinelerra_cv/mob.git] / guicast / bcsignals.h
blob981b3f1f3639e0e455a91e6307fc3dcb0861452f
1 #ifndef BCSIGNALS_H
2 #define BCSIGNALS_H
4 #include "arraylist.h"
5 #include "bcsignals.inc"
6 #include <pthread.h>
7 #include <signal.h>
9 #define TRON(x) BC_Signals::new_function(x);
10 #define TROFF(x) BC_Signals::delete_function(x);
12 // BC_Signals must be initialized at the start of every program using
13 // debugging.
14 #define ENABLE_TRACE
15 #define TRACE_LOCKS
16 //#ifdef TRACE_LOCKS
17 //#undef TRACE_LOCKS
18 //#endif
19 #define TRACE_MEMORY
22 // Need to use structs to avoid the memory manager.
23 // One of these tables is created every time someone locks a lock.
24 // After successfully locking, the table is flagged as being the owner of the lock.
25 // In the unlock function, the table flagged as the owner of the lock is deleted.
26 typedef struct
28 void *ptr;
29 char *title;
30 char *location;
31 int is_owner;
32 int id;
33 } bc_locktrace_t;
35 class BC_Signals
37 public:
38 BC_Signals();
39 void initialize();
40 void initialize2();
43 virtual void signal_handler(int signum);
45 #ifdef ENABLE_TRACE
46 // Add a trace
47 #define TRACE(text) BC_Signals::new_trace(text);
48 #define SET_TRACE BC_Signals::new_trace(__FILE__, __FUNCTION__, __LINE__);
49 #define PRINT_TRACE { printf("%s: %d\n", __FILE__, __LINE__); fflush(stdout); }
50 // Delete all traces
51 #define UNTRACE BC_Signals::delete_traces();
53 #else
55 #define TRACE(text) ;
56 #define UNTRACE ;
57 #define PRINT_TRACE ;
59 #endif
62 #ifdef TRACE_LOCKS
64 // Before user acquires
65 #define SET_LOCK(ptr, title, location) int table_id = BC_Signals::set_lock(ptr, title, location);
66 // After successful acquisition of a mutex, the table is flagged
67 #define SET_LOCK2 BC_Signals::set_lock2(table_id);
68 // After successful acquisition of a condition, the table is removed because
69 // the user never unlocks a condition after locking it.
70 // Release current lock table after failing to acquire
71 #define UNSET_LOCK2 BC_Signals::unset_lock2(table_id);
73 // Release current owner of lock
74 #define UNSET_LOCK(ptr) BC_Signals::unset_lock(ptr);
76 // Delete a lock
77 #define UNSET_ALL_LOCKS(ptr) BC_Signals::unset_all_locks(ptr);
79 #else
81 #define SET_LOCK(ptr, title, location) ;
82 #define SET_LOCK2 ;
83 #define SET_LOCK2_CONDITION ;
84 #define UNSET_LOCK(ptr) ;
85 #define UNSET_LOCK2 ;
86 #define UNSET_ALL_LOCKS(ptr) ;
88 #endif
91 #ifdef TRACE_MEMORY
93 #define ENABLE_BUFFER BC_Signals::enable_memory();
94 #define DISABLE_BUFFER BC_Signals::disable_memory();
95 // Note the size, pointer, and location of an allocation
96 #define BUFFER(size, ptr, location) BC_Signals::set_buffer(size, ptr, location);
97 // Note the pointer and location of an allocation
98 #define BUFFER2(ptr, location) BC_Signals::set_buffer(0, ptr, location);
99 // Remove a pointer from the allocation table
100 #define UNBUFFER(ptr) BC_Signals::unset_buffer(ptr);
102 #else
104 #define ENABLE_BUFFER ;
105 #define DISABLE_BUFFER ;
106 #define BUFFER(size, ptr, location);
107 #define UNBUFFER(ptr);
109 #endif
111 // Handling of temporary files in crash
112 #define SET_TEMP BC_Signals::set_temp
113 #define UNSET_TEMP BC_Signals::unset_temp
115 // Temporary files
116 static void delete_temps();
117 static void set_temp(char *string);
118 static void unset_temp(char *string);
123 static int set_lock(void *ptr, char *title, char *location);
124 static void set_lock2(int table_id);
125 static void set_lock2_condition(int table_id);
126 static void unset_lock2(int table_id);
127 static void unset_lock(void *ptr);
128 // Used in lock destructors so takes away all references
129 static void unset_all_locks(void *ptr);
131 static void new_trace(char *text);
132 static void new_trace(const char *file, const char *function, int line);
133 static void delete_traces();
135 static void enable_memory();
136 static void disable_memory();
137 static void set_buffer(int size, void *ptr, char* location);
138 // This one returns 1 if the buffer wasn't found.
139 static int unset_buffer(void *ptr);
141 static void dump_traces();
142 static void dump_locks();
143 static void dump_buffers();
145 // Convert signum to text
146 static char* sig_to_str(int number);
148 static BC_Signals *global_signals;
152 #endif