📄 suspendthread.c
字号:
/*
* File : RZKSuspendThread.c
*
* Description : This file contains the RZKSuspendThread function which
* suspends the given thread.
*
* 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 <stdio.h>
#include "ZSysgen.h"
#include "ZTypes.h"
#include "ZThread.h"
#include "ZQueue.h"
#include "ZScheduler.h"
#include "ZInterrupt.h"
#define pThread ((RZK_TCB_t *) hThread)
#define pCurrentThread ((RZK_TCB_t *) hCurrentThread)
/** extern functions */
//extern void RZKScheduler();
extern void QueueNodeRemove(RZK_TCB_t *pObjectToRemove );
extern void DispatchQueueNodeRemove(RZK_TCB_t *pObjectToRemove );
/** extern variables */
extern RZK_DISPATCHQ_t DispatchQueue[DMAX_PRIORITY_P1]; /* declared in Createthread.c */
extern RZK_THREADHANDLE_t hCurrentThread; /* declared in Scheduler.c */
extern volatile UINT32 DQPriorityBitMap;
extern const UINT32 pMap[32];
/*
* Function : RZKSuspendThread
*
* Description : This function suspends the given thread infinitely or for a finite
* amount of time
*
* Inputs : hThread -handle to thread
tTicks - Time for suspension
*
* Outputs : RZKERR_INVALID_HANDLE - when specified handle is invalid
RZKERR_SUCCESS - on successful suspension
*
* Dependencies : hCurrentThread - Handle to current thread
*/
RZK_STATUS_t RZKSuspendThread
(
RZK_THREADHANDLE_t hThread,
TICK_t tTicks
)
{
RZK_STATE_t uState;
/* CHECK FOR VALIDITY OF ARGUMENTS */
#ifdef RZK_DEBUG
if ( (pThread == NULL) || (pThread->uState == 0) || (pThread->magic_num !=MAGIC_NUM_THREAD))
return RZKERR_INVALID_HANDLE;
#endif
#ifndef RZK_PERFORMANCE
if( ! (pThread->uState & OBJECT_CREATED) )
return RZKERR_CB_BUSY;
#endif /* RZK_PERFORMANCE */
if(tTicks == 0)
return RZKERR_INVALID_ARGUMENTS;
/* TEST FOR SUSPEND ON ANOTHER THREAD FOR A FINITE TIME */
if((( pThread != pCurrentThread) && (tTicks != MAX_INFINITE_SUSPEND)) ||
(pThread->uState & THREAD_TERMINATED) )
{
return RZKERR_INVALID_OPERATION;
}
uState = RZKDisablePreemption();
/* If the thread is running, then remove it from dispatch queue */
if (pThread->uState & THREAD_RUNNING)
{
UINTRMASK mInterruptMask;
mInterruptMask = RZKDisableInterrupts();
DispatchQueueNodeRemove(pThread);
RZKEnableInterrupts(mInterruptMask);
}
/* If time is infinite, set the infinitesuspend bit in uState */
if (tTicks == MAX_INFINITE_SUSPEND)
pThread->uState |= THREAD_INFINITESUSPEND;
else
{
/* If time is finite, put the thread in time queue1 */
pThread->tWaitTime = tTicks;
AddToTimeQ1(pThread);
pThread->uBlockingReason = BLOCK_TIMEDSUSPEND;
pThread->uState |= THREAD_BLOCKEDSUSPEND;
}
pThread->errNum = RZKERR_SUCCESS;
/* Reset the RUNNING bit */
pThread->uState &= ~(THREAD_RUNNING);
/* Unlock now */
RZKRestorePreemption(uState);
/* RETURN STATUS */
return pCurrentThread->errNum;//Assuming error is cleared in RZKGetErrorNum
} /* End of SuspendThread */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -