Exemple #1
0
UINT CThread::ThreadProc(LPVOID pObject)
{
	ASSERT(pObject);
	ASSERT_KINDOF(CThread, (CObject *)pObject);

	CThread *pThread = (CThread *)pObject;

	// initialisieren, ausführen, aufräumen
	if (pThread->InitInstance())
		pThread->Run();
	UINT nResult = pThread->ExitInstance();

	// den tatsächlich gelieferten Exit-Code setzen
	pThread->SetExitCode(nResult);

	pThread->m_pWinThread = NULL; // zerstört sich selbst
	HANDLE hThreadStoppedEvent = pThread->m_hThreadStoppedEvent;

	// Thread-Objekt ggf. automatisch zerstören
	if (pThread->m_bAutoDelete) delete pThread;

	// Beendigungs-Event setzen; setzt alle Threads fort, die in Join() warten
	VERIFY(SetEvent(hThreadStoppedEvent));

	return nResult;
}
Exemple #2
0
	unsigned __stdcall ThreadProcess(void *pThreadPtr )
	{
		CThread *pThread = (CThread*)pThreadPtr;
		pThread->Run();
		pThread->Exit();
		return 0;
	}
Exemple #3
0
//*********************************************************
//creates the thread
//*********************************************************
int CThread::runProcess (void* Param)
{
	CThread*	thread;
	thread			= (CThread*)((param*)Param)->pThread;
	delete	((param*)Param);
	return thread->Process (0);
}
Exemple #4
0
DWORD CThread::run(LPVOID thread)
{
	CThread* Thread = ((CThread*)thread); 
	Thread->m_Func(Thread->m_Param);
	SetEvent(Thread->m_Exit); 
	return NULL;
}
Exemple #5
0
unsigned int WINAPI  ThreadProc(LPVOID lpParam)
{
	CThread * p = (CThread *) lpParam;
	p->Run();
	_endthreadex(0);
	return 0;
}
Exemple #6
0
 static THREAD_FUN __stdcall ThreadProc(LPVOID lpParam) {
     CThread * pThis = (CThread *)lpParam;
     TASSERT(pThis, "a null thread owner point");
     pThis->Run();
     _endthreadex(0);
     return 0;
 }
Exemple #7
0
void CBackgroundInfoLoader::Load(CFileItemList& items)
{
  StopThread();

  if (items.Size() == 0)
    return;

  CSingleLock lock(m_lock);

  for (int nItem=0; nItem < items.Size(); nItem++)
    m_vecItems.push_back(items[nItem]);

  m_pVecItems = &items;
  m_bStop = false;
  m_bStartCalled = false;

  int nThreads = m_nRequestedThreads;
  if (nThreads == -1)
    nThreads = (m_vecItems.size() / (ITEMS_PER_THREAD+1)) + 1;

  if (nThreads > g_advancedSettings.m_bgInfoLoaderMaxThreads)
    nThreads = g_advancedSettings.m_bgInfoLoaderMaxThreads;

  m_nActiveThreads = nThreads;
  for (int i=0; i < nThreads; i++)
  {
    CThread *pThread = new CThread(this, "Background Loader");
    pThread->Create();
#ifndef _LINUX
    pThread->SetPriority(THREAD_PRIORITY_BELOW_NORMAL);
#endif
    m_workers.push_back(pThread);
  }

}
Exemple #8
0
qboolean G_ClientRunThreadCmd( const gentity_t *ent )
{
	str		threadName;
	CThread	*thread;
	
	Q_UNUSED(ent);

	// Get the thread name
	
	if ( !gi.argc() )
		return true;
	
	threadName = gi.argv( 1 );
	
	
	// Check to make sure player is allowed to run this thread
	
	// Need to do this part
	
	// Run the thread
	
	if ( !threadName.length() )
		return true;
	
	thread = Director.CreateThread( threadName );
	
	if ( thread )
		thread->DelayedStart( 0.0f );
	
	return true;
}
Exemple #9
0
///////////////////////////////////////////////////////////////////////////
// function : start the thread's run() virtual function 
unsigned long __stdcall CThread::ThreadFunction( void *pV )
{
	int result = 0;

	CThread* pThis = (CThread*)pV;
		
	if (pThis)
	{
        CWinSeh::ResetSeh();
		try{
		    result = pThis->Run();
		} // End of try
        catch( std::exception &ex )
        {
            std::cout << "Cpp    Exception : " << ex.what() << std::endl;
        }
        catch( CWinSeh &ex )
        {
            std::cout << "System Exception : " << ex.GetExpCode() << " : " << ex.GetExpDes( ) << std::endl;
        }
		catch(...){
            std::cout << "Get an unknown exception!" << std::endl;
		} // End of catch( ... )
	} // end of if

	return result;
}
Exemple #10
0
int CServerLinker::Monitor(void)
{
    CServerLinkerMonitor *pMonitor = NULL;

    pMonitor = new(std::nothrow) CServerLinkerMonitor();
    if (NULL == pMonitor)
    {
        Q_Printf("%s", Q_EXCEPTION_ALLOCMEMORY);

        return Q_ERROR_ALLOCMEMORY;
    }

    pMonitor->setServerLinker(this);

    try
    {
        CThread objThread;

        //等待线程启动
        m_objMutex.Lock();
        objThread.Execute(pMonitor);
        m_objCond.Wait(&m_objMutex, 1000);
        m_objMutex.unLock();
    }
    catch (CException &e)
    {
        Q_SafeDelete(pMonitor);
        Q_Printf("exception code %d message %s", e.getErrorCode(), e.getErrorMsg());

        return e.getErrorCode();
    }

    return Q_RTN_OK;
}
DWORD WINAPI
#else
LPVOID
#endif
_THKERNEL( LPVOID lpvData /* CThread Object */ 
		  )
{
	CThread *pThread = (CThread *)lpvData;
	ThreadType_t lastType;
	/*
	 *
	 * initialization
	 *
	 */


    pThread->m_mutex.Lock();
		pThread->m_state = ThreadStateWaiting;
		pThread->m_bRunning = TRUE;
#ifndef WINDOWS
		pThread->m_dwId = CThread::ThreadId();
#endif
	pThread->m_mutex.Unlock();
	
	while( TRUE )
	{
		lastType = pThread->m_type;

		if( lastType == ThreadTypeEventDriven )
		{
			if( ! pThread->m_event.Wait()  ) 
					break;
		}
	
		if( ! pThread->KernelProcess() ) 
				break;


		if( lastType == ThreadTypeEventDriven )
			pThread->m_event.Reset();

		if( pThread->m_type == ThreadTypeIntervalDriven )
			Sleep(pThread->m_dwIdle);

	}


	pThread->m_mutex.Lock();
		pThread->m_state = ThreadStateDown;
		pThread->m_bRunning = FALSE;
	pThread->m_mutex.Unlock();


#ifdef WINDOWS
	return 0;
#else
	return (LPVOID)0;
#endif
}
Exemple #12
0
//static method
static void* runProcess (void* pThis)
{
	workAround* wA	= (workAround*)pThis;
	//this will call the appropriate method, as Process is a virtual method
	CThread* thread = wA->this_thread;
	delete wA;
	thread->run();
}
Exemple #13
0
void* CThread::ThreadFunction(void* args)
{
  CThread* thread = reinterpret_cast<CThread*>(args);
  thread->Process();
  thread->m_running = false;

  return NULL;
}
DWORD WINAPI CThread::ThreadProc(LPVOID lpParameter)
{
	   CThread *pThread = (CThread *)lpParameter;
	   if(pThread)
	      return pThread->Execute();
	   else
		  return (DWORD)-1;
}
Exemple #15
0
void* CThread::helper(void* arg)
{
  CThread* p = (CThread*)arg;

  p->entry();

  return NULL;
}
Exemple #16
0
DWORD CThread::helper(LPVOID arg)
{
  CThread* p = (CThread*)arg;

  p->entry();

  return 0UL;
}
void* CThread::Hook(void* args)
{
	CThread* thread = (CThread*) args;
	if (thread->runnuble()) {
		thread->runnuble()->Run(thread, thread->args());
	}
	return (void*)NULL;
}
Exemple #18
0
//=============================================================================
static DWORD WINAPI ThreadEntryPoint (LPVOID param)
{
    CThread * thread = (CThread *)param;
    ASSERT(thread);

    thread->ThreadEnter();

    return 0;
}
	THREAD_FUN CThread::__WorkThread(void *arg)
	{
		CThread *pThis = (CThread*) arg;
#ifdef WIN32
		return pThis->DoRunning();
#else
		pThis->DoRunning();
#endif
	}
Exemple #20
0
void CWorker::WaitForObject() {
   CTrace::CEnter Enter(CTrace::Layer::CODINE, L"Worker::WaitForObject()");

   for (list<CThread*>::iterator it = m_ThreadList.begin(); it != m_ThreadList.end(); it++) {
      CThread *TheThread;
   
      TheThread = *it;
      TheThread->WaitForObject();
   }
}
Exemple #21
0
void CThread::Create(THREAD_EXEC_PROC pExecProc, void *pParam)
{
	CThread *pThread = new CThread();

	pThread->SetFreeOnTerminate(true);
	pThread->m_pExecProc = pExecProc;
	pThread->m_pThreadParam = pParam;

	pThread->Run();
}
void *CThread::ThreadProc(void *obj)
{
      CThread *pThread = static_cast<CThread*>(obj);

      int canc = vlc_savecancel ();
      pThread->Execute();
      vlc_restorecancel (canc);

      return NULL;
}
Exemple #23
0
void	CThread::startup(void* P)
{
	CThread* T = (CThread*)P;

	if (T->thMessages)	clMsg("* THREAD #%d: Started.",T->thID);
	FPU::m64r		();
	T->Execute		();
	T->thCompleted	= TRUE;
	if (T->thMessages)	clMsg("* THREAD #%d: Task Completed.",T->thID);
}
Exemple #24
0
CThread * GameLauncher::loadGameToMemoryAsync(const discHeader *header, sigslot::signal2<const discHeader *, int> * asyncLoadFinished)
{
    asynch_params_t *params = new asynch_params_t;
    params->hdr = header;
    params->asyncLoadFinished = asyncLoadFinished;

    CThread * thread = CThread::create(gameLoadCallback, (void*)params, CThread::eAttributeAffCore1);
    thread->resumeThread();
    return thread;
}
Exemple #25
0
/*
==============
Start

Does all post-spawning setup.  This is NOT called for savegames.
==============
*/
void Level::Start( void )
{
	CThread *gamescript;

	// initialize secrets

	levelVars.SetVariable( "total_secrets", total_secrets );
	levelVars.SetVariable( "found_secrets", found_secrets );
	levelVars.SetVariable( "total_specialItems" , total_specialItems );
	levelVars.SetVariable( "found_specialItems" , found_specialItems );
	levelVars.SetVariable( "total_enemies_spawned", _totalEnemiesSpawned );
	

	FindTeams();

	// call the precache scripts
	
	Precache();

	// start executing the game script

	if ( game_script.length() )
	{
		gi.ProcessLoadingScreen( "$$LoadingScript$$" );

		program.Load( game_script );

		gi.ProcessLoadingScreen( "$$DoneLoadingScript$$" );

		// Create the main thread

		gamescript = Director.CreateThread( "main" );

		if ( gamescript )
		{
			// Run the precache thread if it exists

			if ( gamescript->labelExists( "precache" ) )
			{
				CThread *precache_script;
				precache_script = Director.CreateThread( "precache" );

				if ( precache_script )
					precache_script->DelayedStart( 0.0f );
			}

			// Run the main thread

			gamescript->DelayedStart( 0.0f );
		}
	}

	loadLevelStrings();
	started = true;
}
/*static */
void* CThread::EntryPoint(void * pthis)
{
	
	if(!pthis) return 0;
	CThread * pt = (CThread*)pthis;
#if defined(USE_GMEMORYMANGER)
	s3eMemorySetUserMemMgr(&pt->mgr);
#endif	
	pt->Run( pt->Arg() );
	return 0;
}
Exemple #27
0
unsigned __stdcall CThread::ThreadFun(void* params)
{
    CThread* pThread = (CThread* )params;
    if(NULL != pThread)
    {
        pThread->SetState(enumTHREADS_EXECUTING);
        pThread->Run();
        pThread->SetState(enumTHREADS_FINISHED);
    }
    return 0;
}
Exemple #28
0
//hlavni procedura vlakna
DWORD WINAPI CThread::ThreadProc(void * x)
{
    CThread* myThread = (CThread*) x;
    // pomoci myThread lze j*z pristupovat i k nestatickym clenum tridy
    
    myThread->Start();                // dynamicky volana metoda Start() 
                                    // po jejim vykonani je
                                    // prace vlakna ukoncena 
    return (myThread->threadID);    // opustenim ThreadProc zanika
                                    // pracovni vlakno objektu CThread
};
Exemple #29
0
void
#else
DWORD WINAPI 
#endif
CThreadPool::ThreadEntry(void* lpParam)
{
	//Rout call into instance.
	CThread* pInstance = (CThread*) lpParam;
	pInstance->ThreadFct();
	return 0;
}
Exemple #30
0
unsigned int CThread::ThreadProc( void* pArgs)
{

	CThread* pthread = (CThread*)pArgs;
	pthread->Run(NULL);

	//<By Jackie 2013-6-8>的线程类, 是在heap上申请的, 我们在这里delete掉.
	// 如果声明为局部变量, 那么就会出现提前析构的情况.
	delete pthread;
	return 0;
}