r717: Made the highlighted text color of the menus WHITE
[cinelerra_cv/mob.git] / guicast / bcsignals.h
blobc875046d2883c49bc22c789c2585b0a8429a97de
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__);
50 // Delete all traces
51 #define UNTRACE BC_Signals::delete_traces();
53 #else
55 #define TRACE(text) ;
56 #define UNTRACE ;
58 #endif
61 #ifdef TRACE_LOCKS
63 // Before user acquires
64 #define SET_LOCK(ptr, title, location) int table_id = BC_Signals::set_lock(ptr, title, location);
65 // After successful acquisition
66 #define SET_LOCK2 BC_Signals::set_lock2(table_id);
67 // Release current lock table after failing to acquire
68 #define UNSET_LOCK2 BC_Signals::unset_lock2(table_id);
70 // Release current owner of lock
71 #define UNSET_LOCK(ptr) BC_Signals::unset_lock(ptr);
73 // Delete a lock
74 #define UNSET_ALL_LOCKS(ptr) BC_Signals::unset_all_locks(ptr);
76 #else
78 #define SET_LOCK(ptr, title, location) ;
79 #define SET_LOCK2 ;
80 #define UNSET_LOCK(ptr) ;
81 #define UNSET_LOCK2 ;
82 #define UNSET_ALL_LOCKS(ptr) ;
84 #endif
87 #ifdef TRACE_MEMORY
89 #define ENABLE_BUFFER BC_Signals::enable_memory();
90 #define DISABLE_BUFFER BC_Signals::disable_memory();
91 #define BUFFER(size, ptr, location) BC_Signals::set_buffer(size, ptr, location);
92 #define UNBUFFER(ptr) BC_Signals::unset_buffer(ptr);
94 #else
96 #define ENABLE_BUFFER ;
97 #define DISABLE_BUFFER ;
98 #define BUFFER(size, ptr, location);
99 #define UNBUFFER(ptr);
101 #endif
103 // Handling of temporary files in crash
104 #define SET_TEMP BC_Signals::set_temp
105 #define UNSET_TEMP BC_Signals::unset_temp
107 // Temporary files
108 static void delete_temps();
109 static void set_temp(char *string);
110 static void unset_temp(char *string);
115 static int set_lock(void *ptr, char *title, char *location);
116 static void set_lock2(int table_id);
117 static void unset_lock2(int table_id);
118 static void unset_lock(void *ptr);
119 // Used in lock destructors so takes away all references
120 static void unset_all_locks(void *ptr);
122 static void new_trace(char *text);
123 static void new_trace(const char *file, const char *function, int line);
124 static void delete_traces();
126 static void enable_memory();
127 static void disable_memory();
128 static void set_buffer(int size, void *ptr, char* location);
129 // This one returns 1 if the buffer wasn't found.
130 static int unset_buffer(void *ptr);
132 static void dump_traces();
133 static void dump_locks();
134 static void dump_buffers();
136 // Convert signum to text
137 static char* sig_to_str(int number);
139 static BC_Signals *global_signals;
143 #endif