DWORD WINAPI CThread::staticThread(LPVOID* data) #endif { CThread* pThread = (CThread*)(data); if (!pThread) { CLog::Log(LOGERROR,"%s, sanity failed. thread is NULL.",__FUNCTION__); return 1; } if (pThread->m_ThreadName.empty()) pThread->m_ThreadName = pThread->GetTypeName(); pThread->SetDebugCallStackName(pThread->m_ThreadName.c_str()); CLog::Log(LOGDEBUG,"Thread %s start, auto delete: %d", pThread->m_ThreadName.c_str(), pThread->IsAutoDelete()); currentThread.set(pThread); #ifndef _LINUX /* install win32 exception translator */ win32_exception::install_handler(); #else struct sigaction action; action.sa_handler = term_handler; sigemptyset (&action.sa_mask); action.sa_flags = 0; //sigaction (SIGABRT, &action, NULL); //sigaction (SIGSEGV, &action, NULL); #endif try { pThread->OnStartup(); } #ifndef _LINUX catch (const win32_exception &e) { e.writelog(__FUNCTION__); if( pThread->IsAutoDelete() ) { delete pThread; _endthreadex(123); return 0; } } #endif catch(...) { CLog::Log(LOGERROR, "%s - thread %s, Unhandled exception caught in thread startup, aborting. auto delete: %d", __FUNCTION__, pThread->m_ThreadName.c_str(), pThread->IsAutoDelete()); if( pThread->IsAutoDelete() ) { delete pThread; #ifndef _LINUX _endthreadex(123); #endif return 0; } } try { pThread->Process(); } #ifndef _LINUX catch (const access_violation &e) { e.writelog(__FUNCTION__); } catch (const win32_exception &e) { e.writelog(__FUNCTION__); } #endif catch(...) { CLog::Log(LOGERROR, "%s - thread %s, Unhandled exception caught in thread process, attemping cleanup in OnExit", __FUNCTION__, pThread->m_ThreadName.c_str()); } try { pThread->OnExit(); } #ifndef _LINUX catch (const access_violation &e) { e.writelog(__FUNCTION__); } catch (const win32_exception &e) { e.writelog(__FUNCTION__); } #endif catch(...) { CLog::Log(LOGERROR, "%s - thread %s, Unhandled exception caught in thread exit", __FUNCTION__, pThread->m_ThreadName.c_str()); } if ( pThread->IsAutoDelete() ) { CLog::Log(LOGDEBUG,"Thread %s %"PRIu64" terminating (autodelete)", pThread->m_ThreadName.c_str(), (uint64_t)CThread::GetCurrentThreadId()); delete pThread; pThread = NULL; } else CLog::Log(LOGDEBUG,"Thread %s %"PRIu64" terminating", pThread->m_ThreadName.c_str(), (uint64_t)CThread::GetCurrentThreadId()); // DXMERGE - this looks like it might have used to have been useful for something... // g_graphicsContext.DeleteThreadContext(); #ifndef _LINUX _endthreadex(123); #endif return 0; }