THREADFUNC CThread::staticThread(void* data) { CThread* pThread = (CThread*)(data); std::string name; ThreadIdentifier id; bool autodelete; if (!pThread) { CLog::Log(LOGERROR,"%s, sanity failed. thread is NULL.",__FUNCTION__); return 1; } name = pThread->m_ThreadName; id = pThread->m_ThreadId; autodelete = pThread->m_bAutoDelete; pThread->SetThreadInfo(); CLog::Log(LOGNOTICE,"Thread %s start, auto delete: %s", name.c_str(), (autodelete ? "true" : "false")); currentThread.set(pThread); pThread->m_StartEvent.Set(); pThread->OnStartup(); pThread->Process(); pThread->OnExit(); // lock during termination CSingleLock lock(pThread->m_CriticalSection); pThread->m_ThreadId = 0; pThread->m_TermEvent.Set(); pThread->TermHandler(); lock.Leave(); if (autodelete) { CLog::Log(LOGDEBUG,"Thread %s %"PRIu64" terminating (autodelete)", name.c_str(), (uint64_t)id); delete pThread; pThread = NULL; } else CLog::Log(LOGDEBUG,"Thread %s %"PRIu64" terminating", name.c_str(), (uint64_t)id); return 0; }
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; } CLog::Log(LOGDEBUG,"thread start, auto delete: %d",pThread->IsAutoDelete()); #ifndef _LINUX /* install win32 exception translator */ win32_exception::install_handler(); #else #ifndef __APPLE__ pLocalThread = pThread; #endif 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 #ifdef __APPLE__ // Set the TLS. pthread_setspecific(tlsLocalThread, (void*)pThread); #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 - Unhandled exception caught in thread startup, aborting. auto delete: %d", __FUNCTION__, 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 - Unhandled exception caught in thread process, attemping cleanup in OnExit", __FUNCTION__); } 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 - Unhandled exception caught in thread exit", __FUNCTION__); } if ( pThread->IsAutoDelete() ) { CLog::Log(LOGDEBUG,"Thread %"PRIu64" terminating (autodelete)", (uint64_t)CThread::GetCurrentThreadId()); delete pThread; pThread = NULL; } else CLog::Log(LOGDEBUG,"Thread %"PRIu64" terminating", (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; }