void thread_initialize(void) { thread_type *thread; /* set up logging */ #ifdef THREAD_DEBUG log_initialize(); _logid = log_open("thread.log"); log_set_level(_logid, THREAD_DEBUG); #endif #ifdef DEBUG_MUTEXES /* create all the internal mutexes, and initialize the mutex tree */ _mutextree = avl_tree_new(_compare_mutexes, NULL); /* we have to create this one by hand, because there's no ** mutextree_mutex to lock yet! */ _mutex_create(&_mutextree_mutex); _mutextree_mutex.mutex_id = _next_mutex_id++; avl_insert(_mutextree, (void *)&_mutextree_mutex); #endif thread_mutex_create(&_threadtree_mutex); thread_mutex_create(&_library_mutex); /* initialize the thread tree and insert the main thread */ _threadtree = avl_tree_new(_compare_threads, NULL); thread = (thread_type *)amalloc(sizeof(thread_type)); thread->thread_id = _next_thread_id++; thread->line = 0; thread->file = strdup("main.c"); thread->sys_thread = pthread_self(); thread->create_time = time(NULL); thread->name = strdup("Main Thread"); avl_insert(_threadtree, (void *)thread); _catch_signals(); _initialized = 1; }
void _runtest(const char* filename, int linenum, const char* testname, void (*f)()) { TRACE_ENTER; static sigjmp_buf sigjmpbuf; static jmp_buf jmpbuf; int rc = 0; int code = sigsetjmp(sigjmpbuf, 1); if (code == 0) { code = setjmp(jmpbuf); if (code == 0) { _catch_signals(filename, linenum, testname, &rc, &sigjmpbuf, &jmpbuf); (*f)(); _release_signals(); } else { TRACE_CATCH; rc = code; _release_signals(); } } else { //printf("after siglongjmp\n"); TRACE_CATCH; //printf("after trace_catch\n"); rc = code; _release_signals(); //printf("after release_signals\n"); } if (rc == 0 && __verbose) { printf("Passed %s\n\n", testname); } else if (rc != 0) { __tests_failed++; printf("%s:%d: Failed %s\n\n", filename, linenum, testname); } TRACE_EXIT; }