5 #include "bcsignals.inc"
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
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.
43 virtual void signal_handler(int signum
);
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); }
51 #define UNTRACE BC_Signals::delete_traces();
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);
77 #define UNSET_ALL_LOCKS(ptr) BC_Signals::unset_all_locks(ptr);
81 #define SET_LOCK(ptr, title, location) ;
83 #define SET_LOCK2_CONDITION ;
84 #define UNSET_LOCK(ptr) ;
86 #define UNSET_ALL_LOCKS(ptr) ;
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);
104 #define ENABLE_BUFFER ;
105 #define DISABLE_BUFFER ;
106 #define BUFFER(size, ptr, location);
107 #define UNBUFFER(ptr);
111 // Handling of temporary files in crash
112 #define SET_TEMP BC_Signals::set_temp
113 #define UNSET_TEMP BC_Signals::unset_temp
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
;