⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 events.c

📁 实时多重作业操作系统内核(RTMK)。简单实时多重作业操作系统内核源程序。RTMK支持消息和事件
💻 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() */

⌨️ 快捷键说明

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