📄 resetqueue.c
字号:
/***************************************************
* RZK RTOS
* Copyright (c) 1999, ZiLOG.
* Developed for ZiLOG by DACS,India.
*
* Author : Ram prasad B.E
*
* Creation Date : 13th of April,1999
*
* Revision History : 23-01-01 Shreekanth.B ZIEL
* RZKERR_CB_BUSY return encapsulated by #ifndef RZK_PERFORMANCE
*
* Function : RZKResetQueue
*
* Purpose : Removes all the messages queued up in this queue and resumes
* all the threads waiting on this queue with appropriate status.
* The control block is reset to it's created state.
*
* Inputs : hMessageQueue - handle to the message queue control block to reset
*
* Outputs : RZKERR_SUCCESS - If the message queue was successfully reset.
* RZKERR_CB_BUSY- If the message control block is being used exclusively by other thread.
* RZKERR_INVALID_HANDLE - If the hMessageQueue is invalid.
*
* Dependencies : None.
*
*************************************************************************************************************/
#include "ZSysgen.h"
#include "ZTypes.h"
#include "ZThread.h"
#include "ZQueue.h"
#include "ZMessageQ.h"
#include "ZScheduler.h"
#define pMessageQueue ((RZK_MESSAGEQUEUE_t *) hMessageQueue)
extern RZK_THREADHANDLE_t hCurrentThread;
/** extern functions */
extern UINTRMASK RZKDisableInterrupts();
extern void RZKEnableInterrupts(UINTRMASK);
//extern void RZKScheduler();
//extern void UpdateThreadStatus( RZK_TCB_t * hThread,UINT errNum);
extern void InitializeCircularBuffer(RZK_MESSAGEQUEUE_t * );
RZK_STATUS_t ResetQueue
(
RZK_MESSAGEQHANDLE_t hMessageQueue
)
{
/* Local Variable */
RZK_TCB_t *pTemp;
RZK_STATE_t uState;
/* validate the handle passed */
#ifdef RZK_DEBUG
if((pMessageQueue==NULL) || ( pMessageQueue -> uState == 0 ) ||
( pMessageQueue -> magic_num != MAGIC_NUM_MESSAGEQ ))
return RZKERR_INVALID_HANDLE;
#endif
#ifndef RZK_PERFORMANCE
if(!(pMessageQueue -> uState & OBJECT_CREATED))
return RZKERR_CB_BUSY;
#endif
/* Reset the created bit of uState */
uState = RZKDisablePreemption();
pMessageQueue -> uState &= ~(OBJECT_CREATED);
pTemp = pMessageQueue->pResNext;
/* check whether the threads which are waiting either to send or receive messages are in TimeQ2.If so remove it from TQ2 */
while ( pTemp != NULL)
{
UpdateThreadStatus(pTemp,RZKERR_OBJECT_RESET);
pTemp=pTemp->pResNext;
}
/* Set etWaitingQueue to MESSAGE_NONE */
pMessageQueue -> etWaitingQueue = MESSAGE_NONE;
InitializeCircularBuffer(pMessageQueue);
/* Initialize uMessageSpaceLeft parameter */
pMessageQueue->uMessageSpaceLeft = pMessageQueue->uQueueLength;
/* Set the created flag of the uState */
pMessageQueue->uState |= OBJECT_CREATED;
RZKRestorePreemption(uState);
return RZKERR_SUCCESS;
} /* end of RZKResetQueue */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -