Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members

bcsignals.h

Go to the documentation of this file.
00001 #ifndef BCSIGNALS_H
00002 #define BCSIGNALS_H
00003 
00004 #include "arraylist.h"
00005 #include "bcsignals.inc"
00006 #include <pthread.h>
00007 #include <signal.h>
00008 
00009 #define TRON(x) BC_Signals::new_function(x);
00010 #define TROFF(x) BC_Signals::delete_function(x);
00011 
00012 // BC_Signals must be initialized at the start of every program using
00013 // debugging.
00014 #define ENABLE_TRACE
00015 #define TRACE_LOCKS
00016 //#ifdef TRACE_LOCKS
00017 //#undef TRACE_LOCKS
00018 //#endif
00019 //#define TRACE_MEMORY
00020 
00021 
00022 // Need to use structs to avoid the memory manager.
00023 // One of these tables is created every time someone locks a lock.
00024 // After successfully locking, the table is flagged as being the owner of the lock.
00025 // In the unlock function, the table flagged as the owner of the lock is deleted.
00026 typedef struct 
00027 {
00028         void *ptr;
00029         char *title;
00030         char *location;
00031         int is_owner;
00032         int id;
00033 } bc_locktrace_t;
00034 
00035 class BC_Signals
00036 {
00037 public:
00038         BC_Signals();
00039         void initialize();
00040         void initialize2();
00041 
00042 
00043         virtual void signal_handler(int signum);
00044 
00045 #ifdef ENABLE_TRACE
00046 // Add a trace
00047 #define TRACE(text) BC_Signals::new_trace(text);
00048 #define SET_TRACE BC_Signals::new_trace(__FILE__, __FUNCTION__, __LINE__);
00049 
00050 // Delete all traces
00051 #define UNTRACE BC_Signals::delete_traces();
00052 
00053 #else
00054 
00055 #define TRACE(text) ;
00056 #define UNTRACE ;
00057 
00058 #endif
00059 
00060 
00061 #ifdef TRACE_LOCKS
00062 
00063 // Before user acquires
00064 #define SET_LOCK(ptr, title, location) int table_id = BC_Signals::set_lock(ptr, title, location);
00065 // After successful acquisition
00066 #define SET_LOCK2 BC_Signals::set_lock2(table_id);
00067 // Release current lock table after failing to acquire
00068 #define UNSET_LOCK2 BC_Signals::unset_lock2(table_id);
00069 
00070 // Release current owner of lock
00071 #define UNSET_LOCK(ptr) BC_Signals::unset_lock(ptr);
00072 
00073 // Delete a lock
00074 #define UNSET_ALL_LOCKS(ptr) BC_Signals::unset_all_locks(ptr);
00075 
00076 #else
00077 
00078 #define SET_LOCK(ptr, title, location) ;
00079 #define SET_LOCK2 ;
00080 #define UNSET_LOCK(ptr) ;
00081 #define UNSET_LOCK2 ;
00082 #define UNSET_ALL_LOCKS(ptr) ;
00083 
00084 #endif
00085 
00086 
00087 #ifdef TRACE_MEMORY
00088 
00089 #define ENABLE_BUFFER BC_Signals::enable_memory();
00090 #define DISABLE_BUFFER BC_Signals::disable_memory();
00091 #define BUFFER(size, ptr, location) BC_Signals::set_buffer(size, ptr, location);
00092 #define UNBUFFER(ptr) BC_Signals::unset_buffer(ptr);
00093 
00094 #else
00095 
00096 #define ENABLE_BUFFER ;
00097 #define DISABLE_BUFFER ;
00098 #define BUFFER(size, ptr, location);
00099 #define UNBUFFER(ptr);
00100 
00101 #endif
00102 
00103 // Handling of temporary files in crash
00104 #define SET_TEMP BC_Signals::set_temp
00105 #define UNSET_TEMP BC_Signals::unset_temp
00106 
00107 // Temporary files
00108         static void delete_temps();
00109         static void set_temp(char *string);
00110         static void unset_temp(char *string);
00111 
00112 
00113 
00114 
00115         static int set_lock(void *ptr, char *title, char *location);
00116         static void set_lock2(int table_id);
00117         static void unset_lock2(int table_id);
00118         static void unset_lock(void *ptr);
00119 // Used in lock destructors so takes away all references
00120         static void unset_all_locks(void *ptr);
00121 
00122         static void new_trace(char *text);
00123         static void new_trace(const char *file, const char *function, int line);
00124         static void delete_traces();
00125 
00126         static void enable_memory();
00127         static void disable_memory();
00128         static void set_buffer(int size, void *ptr, char* location);
00129 // This one returns 1 if the buffer wasn't found.
00130         static int unset_buffer(void *ptr);
00131 
00132         static void dump_traces();
00133         static void dump_locks();
00134         static void dump_buffers();
00135 
00136 // Convert signum to text
00137         static char* sig_to_str(int number);
00138 
00139         static BC_Signals *global_signals;
00140 };
00141 
00142 
00143 #endif

Generated on Sun Jan 8 13:26:33 2006 for Guicast-svn by  doxygen 1.4.4