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

📄 rzkdeleteregion.c

📁 zilog的实时操作系统RZK,可以移植到多种处理器上
💻 C
字号:
/*
* File			:	RZKDeleteRegion.c
*
* Description	:	This function contains RZKDeleteRegion function which deletes a region 
*					specified by the handle.
*
* 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 "ZRegion.h"
#include "ZScheduler.h"
#include "ZInterrupt.h"

#define pRegion  ((RZK_REGION_t *) hRegion)

/** extern functions */
//extern void RZKScheduler();
extern void RemoveSegFromOwnerQueue(RZK_HANDLE_t,pRZK_SEGMENT_t);
//extern void UpdateThreadStatus( RZK_TCB_t * hThread,UINT errNum);
extern void Clear_Segment_Entry(pRZK_SEGMENT_t pSeg);

/*
* Function		:	RZKDeleteRegion
*
* Description	:	Deletes a region specified by the handle and resumes all the threads
*					waiting on this region.It sets the uState parameters of the waiting
*					threads to appropriate values and makes the region available for further 
*  					RZKCreateRegion calls.
* 
* Inputs		:	Handle of the region to delete.
*
* Outputs		:	RZKERR_SUCCESS - If successfully deleted or any of the following errors.
*					RZKERR_INVALID_HANDLE - If the handle passed is invalid.
*					RZKERR_CB_BUSY-	If the region to be deleted is being used exclusively by
*					another thread.
*
* Dependencies	:	None
*/

RZK_STATUS_t RZKDeleteRegion(RZK_REGIONHANDLE_t hRegion )
{
	
	RZK_TCB_t * pTemp;
	pRZK_SEGMENT_t pTempSegment;
	RZK_STATE_t uState;
	/* validate the handle passed */
#ifdef RZK_DEBUG
	if((pRegion == NULL) || (pRegion->uState == 0) || (pRegion->magic_num != MAGIC_NUM_REGION))
			return RZKERR_INVALID_HANDLE;
#endif

	if(!(pRegion->uState & OBJECT_CREATED))
		return RZKERR_CB_BUSY;

	if(!(pRegion->uRnDelete))
	{
		if(pRegion->Alloc_List != NULL)
			return RZKERR_INVALID_OPERATION;
	}


	/* Reset the created bit of uState */
	uState = RZKDisablePreemption();
	pRegion -> uState &= ~(OBJECT_CREATED);

	/* Let pTemp point to the first waiting thread in the queue */
	pTemp = pRegion->pResNext;

	while(pTemp != NULL)
	{
			/* This function updates the thread status to appropriate values */
			UpdateThreadStatus(pTemp,RZKERR_OBJECT_DELETED);
			/* Move to the next thread in the  queue */
			pTemp = pTemp->pResNext;
	} /* end of while loop */

	RZKRestorePreemption(uState);

	/* Clear all the region_tabs for the allocated segments in this region*/
	if(pRegion->Alloc_List)
	{
		while((pRegion->Alloc_List)->next != NULL)
		{
			uState = RZKDisablePreemption();
			pTempSegment = (pRegion->Alloc_List)->next;
			(pRegion->Alloc_List)->next = ((pRegion->Alloc_List)->next)->next;
			/*clear the ownership*/
//			RemoveSegFromOwnerQueue(pTempSegment->thread,pTempSegment);
			Clear_Segment_Entry(pTempSegment);
			RZKRestorePreemption(uState);

		}
		uState = RZKDisablePreemption();
		/*clear the ownership*/
//		RemoveSegFromOwnerQueue(pRegion->Alloc_List->thread,pRegion->Alloc_List);
		Clear_Segment_Entry(pRegion->Alloc_List);
		RZKRestorePreemption(uState);
	}

	uState = RZKDisablePreemption();

		/*Clear all the region tabs for the free list segments */
	if(pRegion->Free_List)
	{
		while((pRegion->Free_List)->next != NULL)
		{
			pTempSegment = (pRegion->Free_List)->next;
			(pRegion->Free_List)->next = ((pRegion->Free_List)->next)->next;
			Clear_Segment_Entry(pTempSegment);			

		}
		Clear_Segment_Entry(pRegion->Free_List);

	}
	/* Invalidate the region control block */
  	pRegion->uState = 0;
	RZKRestorePreemption(uState);
	return RZKERR_SUCCESS;
}/* end of RZKDeleteRegion */

⌨️ 快捷键说明

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