zacquirecontrolblock.c

来自「zilog的实时操作系统RZK,可以移植到多种处理器上」· C语言 代码 · 共 68 行

C
68
字号
/*
* File				:		ZAcquireControlBlock.c
*
* Description		:		This file contains definition of AcquireControlBlock function
* 
* 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 "ZMachine.h" // IAR  port not needed
#include "ZInterrupt.h"

/** extern functions */
extern UINTRMASK RZKDisableInterrupts();
extern void RZKEnableInterrupts(UINTRMASK);

/* Function			:		AcquireControlBlock
*
* Description		:		Allocates an empty control block for the required object.	
* 
* Inputs			:		hControlBlock - The base address of the object
*							uMaxCB - Specifies the maximum number of objects.
*							uSizeOfCB - Specifies the size of the control block.
*
* Outputs			:		returns the hControlBlock on success.
*							returns NULL on failure.
*
* Dependencies		:		None
*/
RZK_HANDLE_t AcquireControlBlock
							( 
								RZK_TCB_t *pControlBlock,
								UINT uMaxCB,
								UINT uSizeOfCB
							)
{
	/* Local Variables */
	UINT index; 
	UINTRMASK mInterruptMask;
    CADDR_t pTemp = (CADDR_t) pControlBlock;

	/* Look for a free control block */
	for( index = 0;index < uMaxCB;index++)
	{
		mInterruptMask = RZKDisableInterrupts();
		if( pControlBlock->uState == 0)
		{
				 pControlBlock->uState = OBJECT_BUSY;
				 RZKEnableInterrupts(mInterruptMask);
				 return (RZK_HANDLE_t) pControlBlock;
		}
		RZKEnableInterrupts(mInterruptMask);
		pTemp += uSizeOfCB;
		pControlBlock = (RZK_TCB_t *) pTemp;
	}
	
	return NULL;
}

⌨️ 快捷键说明

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