-#define TOTAL_TRACES 16
-
-void BC_Signals::new_trace(const char *text)
-{
- if(!global_signals) return;
- pthread_mutex_lock(lock);
-
-// Wrap around
- if(execution_table.size >= TOTAL_TRACES)
- {
- overwrite_table(&execution_table, strdup(text));
-// clear_table(&execution_table, 1);
- }
- else
- {
- append_table(&execution_table, strdup(text));
- }
- pthread_mutex_unlock(lock);
-}
-
-void BC_Signals::new_trace(const char *file, const char *function, int line)
-{
- char string[BCTEXTLEN];
- snprintf(string, BCTEXTLEN, "%s: %s: %d", file, function, line);
- new_trace(string);
-}
-
-void BC_Signals::delete_traces()
-{
- if(!global_signals) return;
- pthread_mutex_lock(lock);
- clear_table(&execution_table, 0);
- pthread_mutex_unlock(lock);
-}
-
-// no canceling with lock held
-void BC_Signals::lock_locks(const char *s)
-{
- pthread_mutex_lock(lock);
- last_lock_thread = pthread_self();
- last_lock_title = s;
- last_lock_location = 0;
-}
-
-void BC_Signals::unlock_locks()
-{
- pthread_mutex_unlock(lock);
-}
-
-#define TOTAL_LOCKS 256
-
-int BC_Signals::set_lock(void *ptr,
- const char *title,
- const char *location)
-{
- if(!global_signals) return 0;
- bc_locktrace_t *table = 0;
- int id_return = 0;
-
- pthread_mutex_lock(lock);
- last_lock_thread = pthread_self();
- last_lock_title = title;
- last_lock_location = location;
- if(lock_table.size >= TOTAL_LOCKS)
- clear_table(&lock_table, 0);
-
-// Put new lock entry
- table = new_bc_locktrace(ptr, title, location);
- append_table(&lock_table, table);
- id_return = table->id;
-
- pthread_mutex_unlock(lock);
- return id_return;
-}
-
-void BC_Signals::set_lock2(int table_id)
-{
- if(!global_signals) return;
-
- bc_locktrace_t *table = 0;
- pthread_mutex_lock(lock);
- for(int i = lock_table.size - 1; i >= 0; i--)
- {
- table = (bc_locktrace_t*)lock_table.values[i];
-// Got it. Hasn't been unlocked/deleted yet.
- if(table->id == table_id)
- {
- table->is_owner = 1;
- table->tid = pthread_self();
- pthread_mutex_unlock(lock);
- return;
- }
- }
- pthread_mutex_unlock(lock);
-}
-
-void BC_Signals::unset_lock2(int table_id)
-{
- if(!global_signals) return;
-
- bc_locktrace_t *table = 0;
- pthread_mutex_lock(lock);
- for(int i = lock_table.size - 1; i >= 0; i--)
- {
- table = (bc_locktrace_t*)lock_table.values[i];
- if(table->id == table_id)
- {
- clear_table_entry(&lock_table, i, 1);
- break;
- }
- }
- pthread_mutex_unlock(lock);
-}
-
-void BC_Signals::unset_lock(void *ptr)
-{
- if(!global_signals) return;
-
- bc_locktrace_t *table = 0;
- pthread_mutex_lock(lock);
-
-// Take off currently held entry
- for(int i = 0; i < lock_table.size; i++)
- {
- table = (bc_locktrace_t*)lock_table.values[i];
- if(table->ptr == ptr)
- {
- if(table->is_owner)
- {
- clear_table_entry(&lock_table, i, 1);
- break;
- }
- }
- }
-
- pthread_mutex_unlock(lock);
-}
-
-
-void BC_Signals::unset_all_locks(void *ptr)
-{
- if(!global_signals) return;
- pthread_mutex_lock(lock);
-// Take off previous lock entry
- for(int i = 0; i < lock_table.size; )
- {
- bc_locktrace_t *table = (bc_locktrace_t*)lock_table.values[i];
- if(table->ptr == ptr)
- {
- clear_table_entry(&lock_table, i, 1);
- continue;
- }
- ++i;
- }
- pthread_mutex_unlock(lock);
-}
-
-void BC_Signals::clear_locks_tid(pthread_t tid)
-{
- if(!global_signals) return;
- pthread_mutex_lock(lock);
-// Take off previous lock entry
- for(int i = 0; i < lock_table.size; )
- {
- bc_locktrace_t *table = (bc_locktrace_t*)lock_table.values[i];
- if(table->tid == tid)
- {
- clear_table_entry(&lock_table, i, 1);
- continue;
- }
- ++i;
- }
- pthread_mutex_unlock(lock);
-}
-
-
-void BC_Signals::enable_memory()
-{
- trace_memory = 1;
-}
-
-void BC_Signals::disable_memory()
-{
- trace_memory = 0;
-}
-
-
-void BC_Signals::set_buffer(int size, void *ptr, const char* location)
-{
- if(!global_signals) return;
- if(!trace_memory) return;
-
-//printf("BC_Signals::set_buffer %p %s\n", ptr, location);
- pthread_mutex_lock(lock);
- append_table(&memory_table, new_bc_buffertrace(size, ptr, location));
- pthread_mutex_unlock(lock);
-}
-
-int BC_Signals::unset_buffer(void *ptr)
-{
- if(!global_signals) return 0;
- if(!trace_memory) return 0;
-
- int ret = 1;
- pthread_mutex_lock(lock);
- for(int i = 0; i < memory_table.size; i++)
- {
- if(((bc_buffertrace_t*)memory_table.values[i])->ptr == ptr)
- {
-//printf("BC_Signals::unset_buffer %p\n", ptr);
- clear_table_entry(&memory_table, i, 1);
- ret = 0;
- break;
- }
- }
-
- pthread_mutex_unlock(lock);
-// fprintf(stderr, "BC_Signals::unset_buffer buffer %p not found.\n", ptr);
- return ret;
-}
-