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

📄 zupdatepriorityrecursive.c

📁 zilog的实时操作系统RZK,可以移植到多种处理器上
💻 C
字号:
/*
* File				:	ZUpdatePriorityRecursive.c
*
* Description		:	This file contains definition of UpdatePriorityRecursive routine.
*
* Copyright 2004 ZiLOG Inc.  ALL RIGHTS RESERVED.
*
* This file contains unpublished confidential and proprietary information
* of ZiLOG, Inc.
* NO PART OF THIS WORK MAY BE DUPLICATED, STORED, PUBLISHED OR DISCLOSED 
* IN ANY FORM WITHOUT THE PRIOR WRITTEN CONSENT OF ZiLOG, INC.
* This is not a license and no use of any kind of this work is authorized
* in the absence of a written license granted by ZiLOG, Inc. in ZiLOG's 
* sole discretion 
*/
#include "ZSysgen.h"
#include "ZTypes.h"
#include "ZThread.h"  
#include "ZQueue.h"
#include "ZSemaphore.h"
#include "ZInterrupt.h"

#define pThread ((RZK_TCB_t*)hThread)

extern RZK_DISPATCHQ_t  DispatchQueue[DMAX_PRIORITY_P1];
extern const UINT32 pMap[32];
extern volatile UINT32 DQPriorityBitMap;
/** extern functions */
extern void GetInheritedPriority(RZK_HANDLE_t hThread,RZK_HANDLE_t hBlockingThread);
extern void RemoveFromResourceQueue(RZK_HANDLE_t hControlBlock, RZK_THREADHANDLE_t hThreadToRemove);
extern void AppendToResourceQueue(RZK_HANDLE_t hObject,RZK_THREADHANDLE_t hThread);
extern void QueueNodeRemove(RZK_TCB_t *pObjectToRemove );
extern void QueueAppend(RZK_TCB_t *pInsertionPosition ,RZK_TCB_t *pObjectToAppend);

/* Function			:	UpdatePriorityRecursive
*
* Description		:	This function updates the priority of the threads recursively
*						due to priority inheritance
* 
* Inputs			:	hThread - pointer to the thread whose priority 
*								  has to be updated.
*
* Outputs			:	void.
*							
*
* Dependencies		:	None.
*/
VOID UpdatePriorityRecursive( RZK_HANDLE_t hThread  )
{
	
	/*LOCAL VARIABLES*/
	RZK_SEMAPHORE_t *pResource,*pOwnerResource;
	RZK_TCB_t *pOwner; 
	RZK_THREAD_PRIORITY_t uTempPrio;
	UINT Was_First_Element = 0;

	while(1)
	{
		pResource = (RZK_SEMAPHORE_t *)pThread->pBlockingResource;
		/* Find out the owner thread */
		pOwner = ( RZK_TCB_t * ) pResource->pOwnerThread;
		pOwnerResource =(RZK_SEMAPHORE_t*)pOwner->pBlockingResource;
		
		if(pOwner->cDispPriority == pOwner->uOriginalPriority)
		{
			if((pOwner->cDispPriority) <= (pThread->cDispPriority))
			{
				GetInheritedPriority(pOwner,pThread);
				break;
			}
			else
			{
				pOwner->cInheritedPriority = pThread->cDispPriority;
			}
		}
		else
		{
			GetInheritedPriority(pOwner,NULL);
		}	

		uTempPrio = pOwner->cDispPriority;
		pOwner->cDispPriority = (pOwner-> cInheritedPriority > pOwner-> uOriginalPriority)?pOwner-> uOriginalPriority:pOwner->cInheritedPriority;
			
		if((!(pOwner->uState & THREAD_RUNNING)) && (pOwner->uBlockingReason & (BLOCK_PENDMAILBOX | BLOCK_PENDMESSAGEQUEUE | BLOCK_ACQUIRESEMAPHORE | BLOCK_REGIONWAIT)) && (pOwnerResource->uState & OBJECT_RECV_PRIORITY))
		{	
			Was_First_Element = (pOwnerResource-> pResNext == pOwner);
			RemoveFromResourceQueue(pOwnerResource,pOwner);
			AppendToResourceQueue(pOwnerResource,pOwner);
			if((pOwnerResource->pResNext != pOwner) &&(!Was_First_Element))
			{
				break;
			}
			
			if((pOwner->uBlockingReason != BLOCK_ACQUIRESEMAPHORE) || (!(pOwnerResource->uState & OBJECT_PRIORITY_INHERITANCE)))
			{
				break;
			}
			hThread = pOwner;
		}
		else
		{	
			if( (pOwner->uState & THREAD_RUNNING) && (uTempPrio != pThread->cDispPriority))
			{
				UINTRMASK mInterruptMask;
				mInterruptMask = RZKDisableInterrupts();
				
				QueueNodeRemove(pOwner);

				if(DispatchQueue[uTempPrio].pPrevious == (RZK_TCB_t *) &DispatchQueue[uTempPrio])
				    DQPriorityBitMap &= (~pMap[uTempPrio]);

				QueueAppend(DispatchQueue[pOwner->cDispPriority].pPrevious,pOwner);

		   		DQPriorityBitMap |= pMap[pOwner->cDispPriority];

				RZKEnableInterrupts(mInterruptMask);
			}				
			break;
		}
	}
	return ;
}

⌨️ 快捷键说明

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