CStressTest::CStressTest(int threads_count, int peers_count)
	:	m_ThreadsCount(threads_count)
	,	m_Pool(threads_count)
	,	m_ThreadId(0)
	,	m_PeersCount(peers_count)
{
TRY_CATCH

	// Initialize critical section
	InitializeCriticalSection(
		&m_InfoSection);

	tstring strLocalPeer;
	tstring strRemotePeer;
	tstring strConnect;
	for( int index = 0; index < m_PeersCount; index++ )
	{
		strLocalPeer = Format(_T("peer_%d"), index + 1);
		bool master;
		if( !(index % 2) )
		{
			strRemotePeer = Format(_T("peer_%d"), index + 2);
			master = true;
		}
		else
		{
			strRemotePeer = Format(_T("peer_%d"), index);
			master = false;
		}
		strConnect = Format(_T("conn_%d"), (int)(index/2) + 1);
		m_Info.insert(ThreadInfoEntry(index + 1, ThreadInfo(master, index+1, strConnect, strLocalPeer, strRemotePeer)));
	}

CATCH_THROW()
}
示例#2
0
void sprawl::threading::ThreadManager::AddThread(uint64_t threadFlags)
{
    ThreadData* data = new ThreadData(threadFlags);
    m_threads.PushBack(ThreadInfo(data, std::bind(&ThreadManager::eventLoop_, this, data)));
    FlagGroup*& group = m_flagGroups[threadFlags];
    if(group == nullptr)
    {
        group = new FlagGroup();
    }
    group->events.PushBack(&data->mailbox);
}
ThreadInfo CStressTest::GetThreadInfo()
{
TRY_CATCH
	
	CCritSection section( &m_InfoSection );

	m_ThreadId++;

	ThreadsInfo::iterator index = m_Info.find( m_ThreadId );

	if( index == m_Info.end() )
		return ThreadInfo();

	return index->second;

CATCH_THROW()
}
示例#4
0
    void Debugger::createThreadEvent(const CREATE_THREAD_DEBUG_INFO & createThread)
    {
        //thread housekeeping
        _process->threads.insert({ _debugEvent.dwThreadId,
            ThreadInfo(createThread.hThread,
            _debugEvent.dwThreadId,
            createThread.lpThreadLocalBase,
            createThread.lpStartAddress) });

        //set the current thread
        _thread = _process->thread = &_process->threads.find(_debugEvent.dwThreadId)->second;
        _registers = &_thread->registers;
        if (!_thread->RegReadContext())
            cbInternalError("ThreadInfo::RegReadContext() failed!");

        //call the debug event callback
        cbCreateThreadEvent(createThread, *_thread);
    }
示例#5
0
 CommonThread::CommonThread(string name,  detach_t detach, thread_loop func)
         : _create(T_FALSE), thread_info(name, detach), func(func) {
     this->thread_info = ThreadInfo(name, detach);
 }
示例#6
0
文件: Thread.cpp 项目: OvaUbe/gum
ThreadInfo Thread::get_info() const {
    return ThreadInfo(_impl.get_id(), _name);
}
bool ofxTimeMeasurements::startMeasuring(const string & ID, bool accumulate, bool ifClause){

	string localID = ID;
	if (!enabled) return true;

	uint64_t wastedTime;
	if(internalBenchmark){
		wastedTime = TM_GET_MICROS();
	}

	if (!settingsLoaded){
		loadSettings();
		settingsLoaded = true;
	}

	string threadName = "Thread";
	ThreadId thread = getThreadID();
	bool bIsMainThread = isMainThread(thread);

	if(!bIsMainThread){
		if(Poco::Thread::current()){
			threadName = Poco::Thread::current()->getName();
		}
	}

	mutex.lock();

	unordered_map<ThreadId, ThreadInfo>::iterator threadIt = threadInfo.find(thread);
	ThreadInfo * tinfo = NULL;
	core::tree<string> *tr = NULL;

	bool newThread = threadIt == threadInfo.end();

	if (newThread){ //new thread!

		//cout << "NewThread! " << ID << " " << &thread << endl;
		threadInfo[thread] = ThreadInfo();
		tinfo = &threadInfo[thread];
		tr = &tinfo->tree; //easier to read, tr is our tree from now on

		if (!bIsMainThread){
			tinfo->color = threadColorTable[numThreads%(threadColorTable.size())];
			numThreads++;
		}else{ //main thread
			tinfo->color = hilightColor;
		}
		tinfo->order = numThreads;

		string tName = bIsMainThread ? "Main Thread" : ("T" + ofToString(tinfo->order) + ": " + threadName);
		//init the iterator
		*tr = tName; //thread name is root
		tinfo->tit = (core::tree<string>::iterator)*tr;

	}else{
		tinfo = &threadIt->second;
		tr = &(tinfo->tree); //easier to read, tr is our tree from now on
	}

	if(tinfo->order > 0){
		localID = "T" + ofToString(tinfo->order) + ":" + localID;
	}

	//see if we had an actual measurement, or its a new one
	unordered_map<string, TimeMeasurement*>::iterator tit = times.find(localID);
	TimeMeasurement* t;

	if(tit == times.end()){ //if it wasnt in the tree, append it
		times[localID] = t = new TimeMeasurement();
		unordered_map<string, TimeMeasurementSettings>::iterator it2 = settings.find(localID);
		if (it2 != settings.end()){
			t->settings = settings[localID];
			if(tinfo->tit.out() == tinfo->tit.end()){ //if we are the tree root - we cant be hidden!
				t->settings.visible = true;
			}
		}
		tinfo->tit = tinfo->tit.push_back(localID);

	}else{
		core::tree<string>::iterator temptit = tr->tree_find_depth(localID);
		if(temptit != tr->end()){
			tinfo->tit = temptit;
		}else{
			//cout << "gotcha!" << endl;
			//this is the rare case where we already had a measurement for this ID,
			//but it must be assigned to another old thread bc we cant find it!
			//so we re-add that ID for this thread and update the tree iterator
			tinfo->tit = tinfo->tit.push_back(localID);
		}
		t = tit->second;
	}

	t->key = localID;
	t->life = 1.0f; //
	t->measuring = true;
	t->ifClause = ifClause;
	t->microsecondsStop = 0;
	t->accumulating = accumulate;
	if(accumulate) t->numAccumulations++;
	t->error = false;
	t->frame = currentFrameNum;
	t->updatedLastFrame = true;
	t->microsecondsStart = TM_GET_MICROS();
	t->thread = thread;

	mutex.unlock();

	if(internalBenchmark){
		wastedTimeThisFrame += t->microsecondsStart - wastedTime;
	}

	return t->settings.enabled;
}
示例#8
0
void DebuggerThread::run()
{
	if ( !DebugActiveProcess( debugger->processId ) )
		return;

	DebugSetProcessKillOnExit( FALSE );
	HANDLE hImageFile = NULL;
	//bool go = false;
	//HANDLE target_thread = 0;

	while( !commit_suicide )
	{
		DEBUG_EVENT dbgEvent;
		if ( !WaitForDebugEvent( &dbgEvent, 100 ) )
		{
			//if ( go )
			//{
			//	DWORD t0 = GetTickCount();
			//	CONTEXT threadcontext;
			//	threadcontext.ContextFlags = CONTEXT_i386 | CONTEXT_CONTROL;

			//	HRESULT result = SuspendThread(target_thread);

			//	if(result == 0xffffffff)
			//		__asm int 3

			//	SetThreadPriority( target_thread, THREAD_PRIORITY_TIME_CRITICAL );
			//	result = GetThreadContext(target_thread, &threadcontext);
			//	SetThreadPriority( target_thread, THREAD_PRIORITY_NORMAL );

			//	ResumeThread(target_thread);
			//	
			//	DWORD t1 = GetTickCount();
			//	char buf[256];
			//	sprintf(buf, "%08x - %ims\n", t1, t1 - t0);
			//	OutputDebugString(buf);
			//}
	
			DWORD err = GetLastError();
			continue;
		}

		WaitForSingleObject( hMutex, INFINITE );
		switch (dbgEvent.dwDebugEventCode) 
		{ 
		case EXCEPTION_DEBUG_EVENT:
			SetEvent( readyEvent );
			//go = true;
			break;

		case CREATE_THREAD_DEBUG_EVENT: 
			debugger->hThreads.push_back( ThreadInfo( dbgEvent.dwThreadId, dbgEvent.u.CreateThread.hThread ) );
			break;

		case CREATE_PROCESS_DEBUG_EVENT:
			debugger->hProcess = dbgEvent.u.CreateProcessInfo.hProcess;
			hImageFile = dbgEvent.u.CreateProcessInfo.hFile;
			debugger->hThreads.push_back( ThreadInfo( dbgEvent.dwThreadId, dbgEvent.u.CreateProcessInfo.hThread ) );
			//target_thread = dbgEvent.u.CreateProcessInfo.hThread;
			break;

		case EXIT_THREAD_DEBUG_EVENT: 
			// Display the thread's exit code. 
			break;

		case EXIT_PROCESS_DEBUG_EVENT: 
			// Display the process's exit code. 
			break;

		case LOAD_DLL_DEBUG_EVENT: 
			// Read the debugging information included in the newly 
			// loaded DLL. Be sure to close the handle to the loaded DLL 
			// with CloseHandle.
			break;

		case UNLOAD_DLL_DEBUG_EVENT: 
			// Display a message that the DLL has been unloaded. 
			break;

		case OUTPUT_DEBUG_STRING_EVENT: 
			// Display the output debugging string. 
			break;

		} 

		ReleaseMutex( hMutex );
		ContinueDebugEvent( dbgEvent.dwProcessId, dbgEvent.dwThreadId, DBG_EXCEPTION_NOT_HANDLED );
	}

	if ( hImageFile )
		CloseHandle( hImageFile );

	DebugActiveProcessStop( debugger->processId );
}
示例#9
0
	void ThreadManager::OnCreate() {
		SimpleLock lock(mutex_);
		threads_.emplace(std::this_thread::get_id(), ThreadInfo(kMainThreadName));
	}