⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 uirecycle.c

📁 嵌入工linux开发的源码
💻 C
📖 第 1 页 / 共 2 页
字号:
#include <pr2k.h>
#include <uiWnd.h> 

#include <typedefine.h>
#include <stdio.h> 
#include <uiTimer.h>
#include <uiWnd.h>
#include <uiPrg_mgr.h>
#include "../include/kernel/sema.h"
#include "../include/kernel/schedule.h"
#include "../include/kernel/capable.h"
#include "../include/kernel/gc_lib.h"
#include <exten\m_sema.h>
#include <filesys.h>
#include <kernel/sync.h>

extern struct dLinkList AllThreadList;
//tong extern TyphoonGlobals typhoon ;


// mips in thd_lib.c
/*
#ifdef __WIN32__
struct dLinkList *tcbSearch(threadID searchID)
//int tcbSearch(threadID searchID)
{
	return NULL;
}
#endif
*/

/*************************************************************
Function : releaseTimerByThread()
	Delete the timers of the target thread
Input:
	tid - target thread ID
**************************************************************/
void releaseTimerByThread(HNDL threadID)
{
	TGuiTimer *pTimer, *pNextTimer;
	int ownerThreadID;

	//pTimer =  PdaTimerTable->pPrev;
	pTimer =  PdaTimerTable;

	pNextTimer = 0;

	while(pTimer)
	{
	
		pNextTimer = pTimer->pNext;
		ownerThreadID = pTimer->iOwnerThreadID;
		if(threadID==ownerThreadID)				
			//deletePdaTimer(pTimer);
			_guiTimer_Delete(pTimer);

		pTimer = pNextTimer;
	}

	guiExitWCS();
}

void releaseOrphanTimers(void)
{
	TGuiTimer *pPrevTimer, *pTimerTable;
	int iRet, ownerThreadID;

	pPrevTimer = 0;
	pTimerTable = PdaTimerTable;

	while(pTimerTable)
	{
		ownerThreadID = pTimerTable->iOwnerThreadID;
		iRet = (HNDL)tcbSearch(ownerThreadID);
		if(!iRet)    // not found
		{
			releaseTimerByThread(ownerThreadID);
			if(pPrevTimer)
				pTimerTable = pPrevTimer;
			else
				pTimerTable = PdaTimerTable;
		}
		else
		{
		
			pPrevTimer = pTimerTable;
			pTimerTable = pTimerTable->pNext;
		}
	}

	return;
}



/*************************************************************
Function : releaseWindowsByThread()
	Delete the windows of the target thread
Input:
	t - target thread ID
**************************************************************/
void releaseWindowsByThread(HNDL threadID)
{
	//HNDL hWnd, hPrevWnd;
	TWindow *pWnd, *pPrevWnd;
	int ownerThreadID;

	pWnd = gpWindowsList;
	pPrevWnd = 0;

	guiEnterWCS();

	while (pWnd)
	{		
		//pWnd = (TWindow *)hWnd;	
		ownerThreadID = pWnd->ownerThreadID;
		
		if(ownerThreadID==threadID)
		{
			if(pWnd->checkFlag!=GUI_WIN_CHECK_FLAG) 
			{
				guiExitWCS();
				return;
			}
			
			
			if(pWnd==gpTopWindow)
				gpTopWindow->handle = 0;
			
			if(pWnd->parent)
			{
				_guiWindow_ReleaseResource(pWnd, 0);
			}
			else
			{
				_guiWindow_ReleaseResource(pWnd, 1);
			}
			
			if(pPrevWnd)
				pWnd = pPrevWnd;
			else
				pWnd = gpWindowsList;
			
		}
		else
		{
			pPrevWnd = pWnd;
			pWnd = pWnd->back;
			
		}
	}// end while

	guiExitWCS();
}

void releaseOrphanWindows(void)
{
	TWindow *pWnd, *pPrevWnd;
	int iRet, ownerThreadID;
	//int hWnd;
	
	pWnd = gpWindowsList;

	pPrevWnd = 0;

	while(pWnd)
	{
		ownerThreadID = pWnd->ownerThreadID;
		iRet = (HNDL)tcbSearch(ownerThreadID);

		if(!iRet)  // not found
		{
			releaseWindowsByThread(ownerThreadID);
			if(pPrevWnd)
			{
				pWnd = pPrevWnd;
			}
			else
			{
				pWnd = gpWindowsList;
			}
		}
		else
		{
			pPrevWnd = pWnd;
			pWnd = pWnd->back;
		}
	}

	return;
}

/*************************************************************
Function : releaseAppByThread()
	Unlinked the application with its associated thread
Input:
	tid - target thread ID
**************************************************************/
void releaseAppByThread(HNDL threadID)
{
	struct dLinkList  *pLinkList;
	TPM_APP     *pApp;
	int  appThreadID;

	//pLinkList = pdaGetAppList();
	pLinkList = ApplicationList.back;

	while(pLinkList)
	{
		pApp = (TPM_APP *)pLinkList->elementPointer;
		appThreadID = pApp->mainThreadID;
		if(appThreadID==threadID)
		{
			pApp->mainThreadID = -1;
			// theApp->currentWinHandle = 0;
			pApp->currentWinHandle = 0;
 
			return;        // ???
		}
		pLinkList = pLinkList->back;
	}
}


void releaseOrphanApps()
{
	struct dLinkList  *pAppLinkList;
	TPM_APP     *pApp;
	int mainThreadID, iRet;

	pAppLinkList = &ApplicationList;
	pAppLinkList = pAppLinkList->back;

	while(pAppLinkList)
	{
		pApp = (TPM_APP *)pAppLinkList->elementPointer;
		mainThreadID = pApp->mainThreadID;
		
		if(mainThreadID!=-1)
		{
			iRet = (HNDL)tcbSearch(mainThreadID);
			if(!iRet)
				pApp->mainThreadID = -1;
		}
		pAppLinkList = pAppLinkList->back;


	}


	return;
}

void releaseSemaphoreByThread(HNDL threadID)
{
	// NULL function
	return;
}


/****************************************************************
Function: signalInRecycle
Description:
	signal a semaphore in recycling
Input:
	s - the semaphore
Note:
	This function acts like signal(), except that it only get
	the highest priority thread back to the ready queue and
	no thread switching is involved.
*****************************************************************/
HNDL signalInRecycle(struct semaphore *pSema)
{
	struct dLinkList *pHighestThreadList;
	struct thread    *pHighestThread;
	struct thread    *pWaitingQueue;
	//struct thread    *pHighestThreadNode;
	int flag=0;

	//struct eventInfo threadEventInfo ;

	//pLinkList = pSema->waitingThreads.back;
	// while(pLinkList) 
	while(pSema->waitingThreads.back)
	{		
		flag = 0;            
		//pHighestThreadList = highestPrioritySearch(&(pSema->waitingThreads));
		pHighestThreadList = highestPrioritySearch(&(pSema->waitingThreads));
		pHighestThread = (struct thread *)pHighestThreadList->elementPointer;
		
		pWaitingQueue = WaitingQueuePtr;
		
		while(pWaitingQueue)
		{
		
			if(pWaitingQueue==pHighestThread)
			{
				flag = 1;
				break;
			}

			pWaitingQueue = pWaitingQueue->back;

		}
		
		if(flag)
		{
			removeFrom(pHighestThreadList);
			removeFromSchedQueue(WAITING_QUEUE, pHighestThread); // 0x457
			pHighestThread->waitingTickNO= -1;
			insertToSchedQueue(DELAYED_QUEUE, pHighestThread);
			pSema->currentThreadID = pHighestThread->tid;
			return 1;
		}
		removeFrom(pHighestThreadList);		
		//pLinkList = pLinkList->back;
	}
	
	if(pSema->value < pSema->maxValue)
		pSema->value += 1;

	pSema->currentThreadID = -1;
	return 0;

}


/*************************************************************
Function: signalSemaphoresByThread
	Signal all semaphores that are currently used by the
	target thread and remove the target thread from the
	waiting list of all semaphores
Input:
	tid - target thread ID
Note:
	A thread may be the current users of two or more
	semaphores, so we have to check all semaphores to see
	if the target thread is the current user. However, a
	thread can only wait for one semaphore at any time, so
	we can stop checking the waiting thread list once the
	thread has been found in one waiting list and removed
	from the list.

	This function works only for binary semaphores. In case
	of the other semaphores, only the resources of the
	latest user will be recycled.
**************************************************************/
void signalSemaphoresByThread(int threadID)
{
	struct dLinkList *pCapabilityList, *pSemaThreadList;
	struct dLinkList *pAllThreadList;
	struct thread   *pWaitingThreadQueue;
	struct thread  *pSemaThread, *pNodeThread;
	struct semaphore *pSema;
	struct capability *pCapability; 
	int    semaThreadID;
	int    flag1, flag2, iResourceType;

	flag1 = 1;
	pAllThreadList = AllThreadList.back;

	while(!pAllThreadList)
	{
		pNodeThread = (struct thread *)pAllThreadList->elementPointer;
		pCapabilityList = pNodeThread->capabilityList.back;

		while(pCapabilityList)
		{
			pCapability = (struct capability *)pCapabilityList->elementPointer;
			iResourceType = pCapability->resourceType;
			if(iResourceType==SEMAPHORE)
			{
				pSema = (struct semaphore *)pCapability->resourcePtr;
				semaThreadID = pSema->currentThreadID;
				if(semaThreadID == threadID)    
					signalInRecycle(pSema);

				if(flag1==0) 
					break;

				pSemaThreadList = pSema->waitingThreads.back;
				while(pSemaThreadList)
				{
					flag2 = 0;
					pWaitingThreadQueue = WaitingQueuePtr;
					while(pWaitingThreadQueue)
					{
						pSemaThread = (struct thread *)pSemaThreadList->elementPointer;
						if(pWaitingThreadQueue==pSemaThread)
						{
							flag2 = 1; 
							break;
						}
						pWaitingThreadQueue = pWaitingThreadQueue->back;

					} // end while(pWaitingThreadQueue)

					if(!flag2)
					{
						removeFrom(pSemaThreadList);			
					}
					else
					{

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -