?? events.c
字號:
/************************************************************************
*
* Module name : EVENTS.C
*
* Module description :
* This module contains RTMK event handling functions.
*
* Project : RTMK
*
* Target platform : DOS
*
* Compiler & Library : BC++ 3.1
*
* Author : Richard Shen
*
* Creation date : 16 August, 1995
*
************************************************************************/
#include <rtmk.h>
#include "rtmkloc.h"
/************************************************************************
* Function name : RtmkSend
* Description : Send an event to a process
* :
* Parameters : process - Task control block
* : evCondition - Event mask
* Returns : -
* Author : Richard Shen
* -----------------------------------------------------------------------
* Date By Description
* -----------------------------------------------------------------------
* 16Aug95 RCS Created.
************************************************************************/
void RtmkSend(PROCESS process, uint evCondition)
{
DisableInterrupt();
process->evReceived |= evCondition; /* Update arrived event */
EnableInterrupt();
if ((process->evWait & process->evReceived))
{
/* Expected event mask received */
DisableInterrupt();
readyProcess |= process->procMask; /* Process is ready to run */
process->evWait &= ~evCondition; /* Reset waiting event mask */
EnableInterrupt();
#ifdef __DOS__
if (servingInt == 0 && curProcess->priority < process->priority)
#else
if (curProcess->priority < process->priority)
#endif /* __DOS__ */
{
/* Priority is higher than the current process, switch to it */
Scheduler(process, FALSE);
} /* end of if */
} /* end of if */
} /* RtmkSend() */
/************************************************************************
* Function name : RtmkArrived
* Description : Return arrived events of process
* :
* Parameters : eventMask - Event mask to check
* Returns : Event mask received
* Author : Richard Shen
* -----------------------------------------------------------------------
* Date By Description
* -----------------------------------------------------------------------
* 16Aug95 RCS Created.
************************************************************************/
uint RtmkArrived(uint eventMask)
{
uint received = curProcess->evReceived & eventMask;
if (received)
{
DisableInterrupt();
curProcess->evReceived &= ~received;
EnableInterrupt();
} /* end-of-if */
return(received);
} /* RtmkArrived() */
/************************************************************************
* Function name : RtmkWait
* Description : Put current process to wait for an event mask
* :
* Parameters : eventMask - Event mask to wait for
* Returns : Event mask received
* Author : Richard Shen
* -----------------------------------------------------------------------
* Date By Description
* -----------------------------------------------------------------------
* 16Aug95 RCS Created.
************************************************************************/
uint RtmkWait(uint eventMask)
{
PROCESS nextProcess;
if (eventMask == 0)
{
/* Manual round robin */
if ((nextProcess = curProcess + 1) >= &pcsTable[MAX_TASKS - 1])
nextProcess = NULL;
Scheduler(nextProcess, TRUE);
return(0);
} /* end of if */
DisableInterrupt();
if (!(curProcess->evReceived & eventMask))
{
/* Event not received */
curProcess->evWait = eventMask;
readyProcess &= ~curProcess->procMask; /* Say process not ready */
EnableInterrupt();
Scheduler(NULL, FALSE); /* Switch to next process */
}
else
EnableInterrupt();
/* Event received */
return(RtmkArrived(eventMask));
} /* RtmkWait() */
/************************************************************************
* Function name : RtmkClear
* Description : Reset event mask to wait for
* :
* Parameters : eventMask - Events to clear
* Returns : event mask received
* Author : Richard Shen
* -----------------------------------------------------------------------
* Date By Description
* -----------------------------------------------------------------------
* 16Aug95 RCS Created.
************************************************************************/
uint RtmkClear(uint eventMask)
{
uint events = curProcess->evReceived;
DisableInterrupt();
curProcess->evReceived &= ~eventMask; /* Clear received event mask */
curProcess->evWait &= ~eventMask; /* Clear waiting event mask */
EnableInterrupt();
return(events);
} /* RtmkClear() */
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -