📄 resumethread.c
字号:
/*
* File : RZKResumeThread.c
*
* Description : This file contains the RZKResumeThread function which
* resumes a created or an infinitely suspended 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 "ZSysgen.h"
#include "ZTypes.h"
#include "ZThread.h"
#include "ZQueue.h"
#include "ZScheduler.h"
#include "ZInterrupt.h"
#define pThread ((RZK_TCB_t *) hThread)
/** extern functions */
extern void RZKScheduler( void );
extern void RZKInitStack(RZK_HANDLE_t *, RZK_TCB_t *);
extern void QueueAppend(RZK_TCB_t *pInsertionPosition ,RZK_TCB_t *pObjectToAppend);
extern void DispatchQueueNodeAppend(RZK_TCB_t *pObjectToAppend);
/** extern variables */
extern RZK_DISPATCHQ_t DispatchQueue[DMAX_PRIORITY_P1]; /* declared in Createthread.c */
extern const UINT32 pMap[32];
extern volatile UINT32 DQPriorityBitMap;
extern UINT8 uRegBankBusyBitMap;
/*
* Function : RZKResumeThread
*
* Description : This function resumes a created
* or an infinitely suspended thread.
* The thread's RUNNING bit is set
* and it is added to Dispatch
* Queue.
*
* Inputs : hThread - handle to the thread
*
* Outputs : ERROR_SUCCESS - On successful termination of thread.
* ERROR_INVALID_HANDLE - when the handle passed is invalid.
* ERROR_INVALID_OPERATION - when the operation is invalid
*
* Dependencies : All externs
*/
RZK_STATUS_t RZKResumeThread(RZK_THREADHANDLE_t hThread)
{
RZK_STATE_t uState;
UINTRMASK mInterruptMask;
#ifdef RZK_DEBUG /* Check for Invalid Handle */
if ((pThread == NULL)||(pThread->uState == 0) || (pThread->magic_num != MAGIC_NUM_THREAD))
return RZKERR_INVALID_HANDLE;
if( pThread->uOperationMode & RZK_THREAD_INTERRUPT)
return RZKERR_INVALID_HANDLE;
#endif
#ifndef RZK_PERFORMANCE
if( ! (pThread->uState & OBJECT_CREATED) )
return RZKERR_CB_BUSY;
#endif /* RZK_PERFORMANCE */
if (pThread->uState & THREAD_TERMINATED)
return RZKERR_INVALID_OPERATION;
/* Lock the section */
uState = RZKDisablePreemption();
if (pThread->uState & THREAD_INFINITESUSPEND)
{
/*Reset the bit-flag as an infinitely suspended thread can be resumed */
pThread->uState &= ~(THREAD_INFINITESUSPEND);
/* Then resume the infinitely suspended thread by attaching it to the DQ. */
if (!(pThread->uState & (THREAD_BLOCKEDSUSPEND | THREAD_TIMEDBLOCK)))
{
mInterruptMask = RZKDisableInterrupts();
DispatchQueueNodeAppend(pThread);
RZKEnableInterrupts(mInterruptMask);
pThread->uState |= THREAD_RUNNING;
}
RZKRestorePreemption(uState);
return RZKERR_SUCCESS;
}
else
if((pThread->uState & THREAD_BLOCKEDSUSPEND) &&
(pThread->uBlockingReason & BLOCK_TIMEDSUSPEND) )
{
UpdateTQ1OnRemove(pThread);
mInterruptMask = RZKDisableInterrupts();
/* Append to dispatch queue */
DispatchQueueNodeAppend(pThread);
RZKEnableInterrupts(mInterruptMask);
/* Thread state must be made running */
pThread->uState |= THREAD_RUNNING;
/* Update blocking reason and uState flag */
pThread->uBlockingReason = 0;
pThread->uState &= ~(THREAD_BLOCKEDSUSPEND);
RZKRestorePreemption(uState);
return RZKERR_SUCCESS;
}
else
{
RZKRestorePreemption(uState);
return RZKERR_INVALID_OPERATION;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -