Beispiel #1
0
THREADFUNC CThread::staticThread(void *data) 
{
	CThread* pThread = (CThread*)(data);
	std::string name;
	ThreadIdentifier id;
	bool autodelete;

	if (!pThread) 
	{
		LOG(LOG_ERROR, "sanity failed. thread is NULL.", NULL);
		return 1;
	}

	name = pThread->m_ThreadName;
	id = pThread->m_ThreadId;
	autodelete = pThread->m_bAutoDelete;

	pThread->SetThreadInfo();

	LOG(LOG_INFO,"Thread %s start, auto delete: %s", name.c_str(), (autodelete ? "true" : "false"));

	currentThread.set(pThread);
	pThread->m_StartEvent.Set();

	pThread->Action();

	// lock during termination
	XR::CSingleLock lock(pThread->m_CriticalSection);

	pThread->m_ThreadId = 0;
	pThread->m_TermEvent.Set();
	pThread->TermHandler();

	lock.Leave();

	if (autodelete) 
	{
		LOG(LOG_DEBUG,"Thread %s %d terminating (autodelete)", name.c_str(), (DWORD)id);
		delete pThread;
		pThread = NULL;
	} else 
	{
		LOG(LOG_DEBUG,"Thread %s %d terminating", name.c_str(), (DWORD)id);
	}

	return 0;
}
Beispiel #2
0
THREADFUNC CThread::staticThread(void* data)
{
  CThread* pThread = static_cast<CThread*>(data);
  std::string name;
  ThreadIdentifier id;
  bool autodelete;

  if (!pThread) {
    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();

  LOG(LOGDEBUG,"Thread %s start, auto delete: %s", name.c_str(), (autodelete ? "true" : "false"));

  currentThread.set(pThread);
  pThread->m_StartEvent.Set();

  pThread->Action();

  // lock during termination
  CSingleLock lock(pThread->m_CriticalSection);

  pThread->m_ThreadId = 0;
  pThread->m_TermEvent.Set();
  pThread->TermHandler();

  lock.Leave();

  if (autodelete)
  {
    LOG(LOGDEBUG,"Thread %s %" PRIu64" terminating (autodelete)", name.c_str(), (uint64_t)id);
    delete pThread;
    pThread = NULL;
  }
  else
    LOG(LOGDEBUG,"Thread %s %" PRIu64" terminating", name.c_str(), (uint64_t)id);

  return 0;
}