Ejemplo n.º 1
0
int piunlock (pimutex_t *mtx){
	Initialize();	
	
	TCB_t* blocked;
	
	
	if(mtx != NULL){
		//IF MUTEX IS ALREADY LOCKED BY ANOTHER THREAD
		if(mtx->flag == 0){
			
			//UNLOCK MUTEX
			mtx->flag = 1;
			blocked = mtx->first;
			
			if(blocked){
				
				blocked->next = NULL;
				mutexBlockedThreads = RemoveThread(mutexBlockedThreads, blocked->tid);
				
				mtx->first = RemoveFromMutex(mtx->first);
				
				if(blocked->credReal){
					activeThreads = AddThread(activeThreads, blocked);
				}
				else{
					expiredThreads = AddThread(expiredThreads, blocked);
				}
			}
			return 0;
		}
	}
	
	
	return -1;
}
Ejemplo n.º 2
0
void unblock(){
	
	
	TCB_t* blockedThread = NULL;
	WaitQueue_t* waited = NULL;

	//IF THERE ARE THREADS TO BE WAITED FOR
	if(waitTids){

		//VERIFY IF THE FINISHED THREAD IS WAITED
		//FOR ANOTHER THREAD
		waited = GetWait(waitTids,runningThread->tid);
		if(waited){

			//FIND THE CORRESPONDING BLOCKED THREAD,
			//REMOVES IT FROM THE BLOCKED THREADS LIST
			//AND ADDS IT TO THE ABLE THREADS LIST
			blockedThread = GetThread(blockedThreads, waited->waiting);

			blockedThread->state = ABLE;

			blockedThreads = RemoveThread(blockedThreads, blockedThread->tid);
			waitTids = RemoveWait(waitTids,runningThread->tid);

			activeThreads = AddThread(activeThreads, blockedThread);
		}
	}
}
Ejemplo n.º 3
0
int killthread_cmd(int argc, char **argv, FF_ENVIRONMENT *pEnv) {
	THREAD hThread;
	int threadID;

	if(!pEnv) {
		return 0;
	}

	if(argc == 2) {
		sscanf(argv[1], "%d", &threadID);
		hThread = GetThread(threadID);
		if(hThread) {
			
			/*TerminateThread(hThread->hThread, &dwExitCode);*/
			hThread->tKill = FF_TRUE;
			while(!hThread->isDead);
			FF_Close(hThread->pFile);
			CloseHandle(hThread->hThread);
			RemoveThread(hThread);
		}
	} else {
		printf("Usage: %s [Thread ID]\n", argv[0]);
	}

	return 0;
}
Ejemplo n.º 4
0
bool
Team::RemoveThread(thread_id threadID)
{
	Thread* thread = ThreadByID(threadID);
	if (thread == NULL)
		return false;

	RemoveThread(thread);
	thread->ReleaseReference();
	return true;
}
Ejemplo n.º 5
0
void KillAllThreads(void) {
	while(g_ThreadList) {
		g_ThreadList->tKill = FF_TRUE;	// Signal Thread to Die.
		
		while(!g_ThreadList->isDead);	// Wait on Thread to Signal its death.
		
		FF_Close(g_ThreadList->pFile);	// Close the file.

		CloseHandle(g_ThreadList->hThread);	// Close thread handle.
		
		RemoveThread(g_ThreadList);	// Remove thread from list.
	}
}
Ejemplo n.º 6
0
	int Run(LPTSTR lpstrCmdLine, int nCmdShow)
	{
		MSG msg;
		// force message queue to be created
		::PeekMessage(&msg, NULL, WM_USER, WM_USER, PM_NOREMOVE);

		AddThread(lpstrCmdLine, nCmdShow);

		int nRet = m_dwCount;
		DWORD dwRet;
		while(m_dwCount > 0)
		{
			dwRet = ::MsgWaitForMultipleObjects(m_dwCount, m_arrThreadHandles, FALSE, INFINITE, QS_ALLINPUT);

			if(dwRet == 0xFFFFFFFF)
			{
				::MessageBox(NULL, _T("ERROR: Wait for multiple objects failed!!!"), _T("TradeYM"), MB_OK);
			}
			else if(dwRet >= WAIT_OBJECT_0 && dwRet <= (WAIT_OBJECT_0 + m_dwCount - 1))
			{
				RemoveThread(dwRet - WAIT_OBJECT_0);
			}
			else if(dwRet == (WAIT_OBJECT_0 + m_dwCount))
			{
				if(::PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
				{
					if(msg.message == WM_USER)
						AddThread(_T(""), SW_SHOWNORMAL);
				}
			}
			else
			{
				::MessageBeep((UINT)-1);
			}
		}

		return nRet;
	}
Ejemplo n.º 7
0
static void HandleTerminateThread( struct TDebug *obj, int thread )
{
    RemoveThread( obj, thread );
}
Ejemplo n.º 8
0
bool Pdb::RunToException()
{
	DR_LOG("RunToException");
	LLOG("RUN TO EXCEPTION");
	TimeStop ts;
	bool disasfocus = disas.HasFocus();
	bool locked = false;
	bool frestored = false;
	invalidpage.Clear();
	mempage.Clear();
	int opn = 0;
	for(;;) {
		if(terminated) {
			if(locked)
				Unlock();
			return false;
		}
		opn++;
		DR_LOG("WaitForDebugEvent");
		if(WaitForDebugEvent(&event, 0)) {
			DR_LOG("WaitForDebugEvent ended");
			debug_threadid = event.dwThreadId;
			opn = 0;
			running = false;
			switch(event.dwDebugEventCode) {
			case EXCEPTION_DEBUG_EVENT: {
				DR_LOG("EXCEPTION_DEBUG_EVENT");
				LLOG("Exception: " << FormatIntHex(event.u.Exception.ExceptionRecord.ExceptionCode) <<
				     " at: " << FormatIntHex(event.u.Exception.ExceptionRecord.ExceptionAddress) <<
				     " first: " << event.u.Exception.dwFirstChance);
				SaveForeground();
				const EXCEPTION_RECORD& x = event.u.Exception.ExceptionRecord;
				if(findarg(x.ExceptionCode, EXCEPTION_BREAKPOINT, EXCEPTION_SINGLE_STEP,
				                            STATUS_WX86_BREAKPOINT, STATUS_WX86_SINGLE_STEP) < 0)
				{
					LLOG("Non-debug EXCEPTION");
					if(event.u.Exception.dwFirstChance) {
						LLOG("First chance " << FormatIntHex(x.ExceptionCode));
						break;
					}
					String desc = Format("Exception: [* %lX] at [* %16llX]&",
					                     (int64)x.ExceptionCode, (int64)x.ExceptionAddress);
					for(int i = 0; i < __countof(ex_desc); i++)
						if(ex_desc[i].code == x.ExceptionCode)
							desc << "[* " << DeQtf(ex_desc[i].text) << "]&";
					if(x.ExceptionCode == EXCEPTION_ACCESS_VIOLATION) {
						desc << (x.ExceptionInformation[0] ? "[*@3 writing]" : "[*@4 reading]");
						desc << Format(" at [* %08llX]", (int64)x.ExceptionInformation[1]);
					}
					ToForeground();
					PromptOK(desc);
				}
#ifdef CPU_64
				if(!win64 && x.ExceptionCode == EXCEPTION_BREAKPOINT && !break_running) // Ignore x64 breakpoint in wow64
					break;
#endif
				if(break_running)
					debug_threadid = mainThreadId;
				break_running = false;
				ToForeground();
				if(disasfocus)
					disas.SetFocus();
				if(locked)
					Unlock();
				if(refreshmodules)
					LoadModuleInfo();
				LLOG("event.dwThreadId = " << event.dwThreadId);
				bool isbreakpoint = findarg(x.ExceptionCode, EXCEPTION_BREAKPOINT, STATUS_WX86_BREAKPOINT) >= 0;
				for(int i = 0; i < threads.GetCount(); i++) {
					Thread& t = threads[i];
					(Context&)t = ReadContext(threads[i].hThread);
					if(event.dwThreadId == threads.GetKey(i)) {
						LLOG("Setting current context");
						if(isbreakpoint
#ifdef CPU_64
						   && bp_set.Find((win64 ? t.context64.Rip : t.context32.Eip) - 1) >= 0
#else
						   && bp_set.Find(t.context32.Eip - 1) >= 0
#endif
						) // We have stopped at breakpoint, need to move address back
					#ifdef CPU_64
							if(win64)
								t.context64.Rip--;
							else
					#endif
								t.context32.Eip--;
						context = t;
					}
				}
				RemoveBp();
				return true;
			}
			case CREATE_THREAD_DEBUG_EVENT:
				DR_LOG("CREATE_THREAD_DEBUG_EVENT");
				LLOG("Create thread: " << event.dwThreadId);
				AddThread(event.dwThreadId, event.u.CreateThread.hThread);
				break;
			case EXIT_THREAD_DEBUG_EVENT:
				DR_LOG("EXIT_THREAD_DEBUG_EVENT");
				LLOG("Exit thread: " << event.dwThreadId);
				RemoveThread(event.dwThreadId);
				break;
			case CREATE_PROCESS_DEBUG_EVENT:
				DR_LOG("CREATE_PROCESS_DEBUG_EVENT");
				LLOG("Create process: " << event.dwProcessId);
				processid = event.dwProcessId;
				AddThread(event.dwThreadId, event.u.CreateProcessInfo.hThread);
				CloseHandle(event.u.CreateProcessInfo.hFile);
				CloseHandle(event.u.CreateProcessInfo.hProcess);
				break;
			case EXIT_PROCESS_DEBUG_EVENT:
				DR_LOG("EXIT_PROCESS_DEBUG_EVENT");
				LLOG("Exit process: " << event.dwProcessId);
				if(locked)
					Unlock();
				terminated = true;
				return false;
			case LOAD_DLL_DEBUG_EVENT: {
				DR_LOG("LOAD_DLL_DEBUG_EVENT");
				LLOG("Load dll: " << event.u.LoadDll.lpBaseOfDll);
				CloseHandle(event.u.LoadDll.hFile);
				refreshmodules = true;
				break;
			}
			case UNLOAD_DLL_DEBUG_EVENT:
				DR_LOG("UNLOAD_DLL_DEBUG_EVENT");
				LLOG("UnLoad dll: " << event.u.UnloadDll.lpBaseOfDll);
				refreshmodules = true;
				break;
			case RIP_EVENT:
				DR_LOG("RIP_EVENT");
				LLOG("RIP!");
				Exclamation("Process being debugged died unexpectedly!");
				terminated = true;
				if(locked)
					Unlock();
				return false;
			}
			DR_LOG("ContinueDebugEvent");
			ContinueDebugEvent(event.dwProcessId, event.dwThreadId, DBG_EXCEPTION_NOT_HANDLED);
			running = true;
		}
		if(ts.Elapsed() > 200) {
			DR_LOG("ts.Elpsed() > 200");
			if(!lock) {
				Lock();
				locked = true;
			}
			if(!frestored) {
				RestoreForeground();
				frestored = true;
			}
		}
		if(lock) {
			DR_LOG("GuiSleep");
			GuiSleep(opn < 1000 ? 0 : 100);
			Ctrl::ProcessEvents();
		}
		else {
			DR_LOG("Sleep");
			Sleep(opn < 1000 ? 0 : 100);
		}
	}
}
Ejemplo n.º 9
0
bool CODebugger::run(unsigned int msec)
{
	DEBUG_EVENT	deDebugEvent;	//调试事件信息
	bool bResult = true;

	// 等待调试事件
	if(m_bActive && WaitForDebugEvent(&deDebugEvent, msec)) 
	{
		//处理调试事件
		switch(deDebugEvent.dwDebugEventCode)
		{ 
			//调试异常事件
		case EXCEPTION_DEBUG_EVENT:
			{
				bResult = OnDebugException(deDebugEvent);
				break;
			}

			//创建线程
		case CREATE_THREAD_DEBUG_EVENT: 	
			{
				AddThread(deDebugEvent.dwThreadId,
					deDebugEvent.u.CreateThread.hThread,
					(DWORD)deDebugEvent.u.CreateThread.lpStartAddress,
					(DWORD)deDebugEvent.u.CreateThread.lpThreadLocalBase);

				// call overloady
				D_CreateThread(&deDebugEvent);

				break;
			}

			//创建进程
		case CREATE_PROCESS_DEBUG_EVENT:
			{
				//m_hProcess = deDebugEvent.u.CreateProcessInfo.hProcess;
				//m_hThread = deDebugEvent.u.CreateProcessInfo.hThread;				

				//将主线程添加到线程链表
				DEBUGGER_THREAD* pDebuggerThread = AddThread(deDebugEvent.dwThreadId,deDebugEvent.u.CreateProcessInfo.hThread,0,0);
				pDebuggerThread->m_bIsMainThread = true;

				// call overloady
				D_CreateProcess(&deDebugEvent);

				// 关闭进程文件句柄
				if(deDebugEvent.u.CreateProcessInfo.hFile)
				{
					CloseHandle(deDebugEvent.u.CreateProcessInfo.hFile);
				}

				break;
			}

			//结束线程
		case EXIT_THREAD_DEBUG_EVENT: 		
			{
				RemoveThread(deDebugEvent.dwThreadId);

				// call overloady
				D_ExitThread(&deDebugEvent);

				break;
			}			

			//结束进程
		case EXIT_PROCESS_DEBUG_EVENT:	
			{
				if(exitfunc != NULL) 
				{					
					(*exitfunc)(&deDebugEvent);
				}				

				// call overloady
				D_ExitProcess(&deDebugEvent);

				break;
			}			

			//加载DLL
		case LOAD_DLL_DEBUG_EVENT: 		
			{				
				break;
			}			

			//卸载DLL
		case UNLOAD_DLL_DEBUG_EVENT: 		
			break;

			//输出调试字符串
		case OUTPUT_DEBUG_STRING_EVENT: 
			{
				// call overloady
				D_OutputDebugString(&deDebugEvent);

				break;
			}
		default:
			{
				bResult = false;
			}
		}

		DWORD dwContinueStatus;
		dwContinueStatus = bResult?DBG_CONTINUE:DBG_EXCEPTION_NOT_HANDLED;
		ContinueDebugEvent(deDebugEvent.dwProcessId, deDebugEvent.dwThreadId,dwContinueStatus);
	}
	else
	{
		return false;
	}

	return true;
}
Ejemplo n.º 10
0
void CPUThreadManager::Close()
{
	m_raw_spu_num = 0;
	while(m_threads.GetCount()) RemoveThread(m_threads[0].GetId());
}
Ejemplo n.º 11
0
void CPUThreadManager::Close()
{
	while(m_threads.size()) RemoveThread(m_threads[0]->GetId());
}
Ejemplo n.º 12
0
//thread function, gets nodes from the nodelist and processes them
void BuildTreeThread( int threadid ) {
	node_t *newnode, *node;
	side_t *bestside;
	int i, totalmem;
	bspbrush_t *brushes;

	for ( node = NextNodeFromList(); node; )
	{
		//if the nodelist isn't empty try to add another thread
		//if (NodeListSize() > 10) AddThread(BuildTreeThread);
		//display the number of nodes processed so far
		if ( numthreads == 1 ) {
			IncreaseNodeCounter();
		}

		brushes = node->brushlist;

		if ( numthreads == 1 ) {
			totalmem = WindingMemory() + c_nodememory + c_brushmemory;
			if ( totalmem > c_peak_totalbspmemory ) {
				c_peak_totalbspmemory = totalmem;
			} //end if
			c_nodes++;
		} //endif

		if ( drawflag ) {
			DrawBrushList( brushes, node );
		} //end if

		if ( cancelconversion ) {
			bestside = NULL;
		} //end if
		else
		{
			// find the best plane to use as a splitter
			bestside = SelectSplitSide( brushes, node );
		} //end else
		  //if there's no split side left
		if ( !bestside ) {
			//create a leaf out of the node
			LeafNode( node, brushes );
			if ( node->contents & CONTENTS_SOLID ) {
				c_solidleafnodes++;
			}

			if ( create_aas ) {
				//free up memory!!!
				FreeBrushList( node->brushlist );
				node->brushlist = NULL;
			} //end if
			  //free the node volume brush (it is not used anymore)
			if ( node->volume ) {
				FreeBrush( node->volume );
				node->volume = NULL;
			} //end if
			node = NextNodeFromList();
			continue;
		} //end if

		// this is a splitplane node
		node->side = bestside;
		node->planenum = bestside->planenum & ~1;   //always use front facing

		//allocate children
		for ( i = 0; i < 2; i++ )
		{
			newnode = AllocNode();
			newnode->parent = node;
			node->children[i] = newnode;
		} //end for

		//split the brush list in two for both children
		SplitBrushList( brushes, node, &node->children[0]->brushlist, &node->children[1]->brushlist );

		CheckBrushLists( node->children[0]->brushlist, node->children[1]->brushlist );
		//free the old brush list
		FreeBrushList( brushes );
		node->brushlist = NULL;

		//split the volume brush of the node for the children
		SplitBrush( node->volume, node->planenum, &node->children[0]->volume,
					&node->children[1]->volume );

		if ( !node->children[0]->volume || !node->children[1]->volume ) {
			Error( "child without volume brush" );
		} //end if

		//free the volume brush
		if ( node->volume ) {
			FreeBrush( node->volume );
			node->volume = NULL;
		} //end if

		//add both children to the node list
		//AddNodeToList(node->children[0]);
		AddNodeToList( node->children[1] );
		node = node->children[0];
	} //end while
	RemoveThread( threadid );
} //end of the function BuildTreeThread
Ejemplo n.º 13
0
void CPUThreadManager::Close()
{
	m_raw_spu_num = 0;
	while(m_threads.size()) RemoveThread(m_threads[0]->GetId());
}
Ejemplo n.º 14
0
void PPCThreadManager::Close()
{
	while(m_threads.GetCount()) RemoveThread(m_threads[0].GetId());
}