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

📄 mos.h

📁 语法分析器 完成从c/c++向C++转变
💻 H
字号:
#ifdef  MOS_H
#else
#define MOS_H

//////////////////////////////////////////////////////////////////////// 
// 
//  Module Name:  mos.h
// 
//  Description:  MOS include for class definitions 
// 
//  Written by:   John Tal 
// 
// 
//  Modification history: 
// 
//  Date         Engineer     Mod #          Modification Description 
// 
//  12-Feb-1992  Tal          v 1.0-001      Initial conversion to C++ 
// 
//////////////////////////////////////////////////////////////////////// 
 

//  Implementation of MOS classes is as follows:
//      
//       MSG_C  - Interprocess messaging
//       SEM_C  - Semaphores   (accessed by MOS_C only)
//       PROC_C - Process Info (accessed by MOS_C only)
//       MOS_C  - Operating System APIs for application usage


//
//  Message Class - Accessed by MOS and application
//
 
class MSG_C
{
private:
   SHORT   sSendPid;
   SHORT   sDestPid;
   SHORT   sLen;
   PCHAR   pcData;

public:

   MSG_C(VOID) { };
   ~MSG_C(VOID) { };                  // inline functions for data access

   SHORT   GetSendPid(VOID)        { return sSendPid; }
   VOID    SetSendPid(SHORT sParm) { sSendPid = sParm; }

   SHORT   GetDestPid(VOID)        { return sDestPid; }
   VOID    SetDestPid(SHORT sParm) { sDestPid = sParm; }
   
   SHORT   GetLen(VOID)            { return sLen; }
   VOID    SetLen(SHORT sParm)     { sLen = sParm; }
   
   PCHAR   GetData(VOID)           { return pcData; }
   VOID    SetData(PCHAR pcParm)   { pcData = pcParm; }
};

typedef MSG_C * MSG_P;





//
//  Semaphore class - accessed only by MOS
//

typedef short SEM_HANDLE;

class SEM_C
{

private:

#define  SEM_NAME_LEN 32

   SHORT sVal;
   CHAR  szName[SEM_NAME_LEN + 1];
   BOOL  fInUse;
   SHORT sHandle;

public:

#define  SEM_AVAIL  0

   //
   //  Semaphore handlers
   //

   SEM_C(VOID)  { };
   ~SEM_C(VOID) { };

   QUEUE_C clQueSemWait;    // processes waiting for this semaphore
   
   PCHAR   GetName(VOID)          { return szName; }
   VOID    SetName(PCHAR pcParm)  { strcpy(szName,pcParm); } 

   SHORT   GetVal(VOID)           { return sVal; }
   VOID    SetVal(SHORT sParm)    { sVal = sParm; }

   BOOL    GetfInUse(VOID)        { return fInUse; }
   VOID    SetfInUse(BOOL fParm)  { fInUse = fParm; }

   SHORT   GetHandle(VOID)        { return sHandle; }
   VOID    SetHandle(SHORT sParm) { sHandle = sParm; }
};

typedef SEM_C * SEM_P;




//
//  Process States
//
   
#define  PROC_STATE_SUSPENDED -3
#define  PROC_STATE_NO_EXIST  -2

// dont use 0 or -1 cause C++ or operating system probably does

#define  PROC_STATE_RUNNING   1
#define  PROC_STATE_READY     2
#define  PROC_STATE_SLEEPING  3
#define  PROC_STATE_SEM_WAIT  4
#define  PROC_STATE_MSG_WAIT  5



class MOS_C;


//  Process Class - Accessed only by MOS

class PROC_C
{

private:
   
   #define  PROC_NAME_LEN    16
   
   SHORT  sProcId;
   CHAR   szName[PROC_NAME_LEN + 1];
   SHORT  sPriority;             
   SHORT  sState;             
   SHORT  sPrevState;      
   LONG   lWakeTime;
   BOOL   fCritical;               // set if cannot swap out
   BOOL   fStateChanged;           // set if OS needs to look at
   PVOID  pvWorkArea;

public:


   PROC_C(VOID)  { };
   ~PROC_C(VOID) { };

   //  Will be accessed by MOS only, not application 'process'

   SHORT  GetId(VOID)              { return sProcId; }
   VOID   SetId(SHORT sParm)       { sProcId = sParm; }

   PCHAR  GetName(VOID)            { return szName; }
   VOID   SetName(PCHAR pcParm)    { strcpy(szName,pcParm); } 

   SHORT  GetPriority(VOID)        { return sPriority; }
   VOID   SetPriority(SHORT sParm) { sPriority = sParm; }

   SHORT  GetState(VOID)           { return sState; }
   VOID   SetState(SHORT sParm)    { sState = sParm; }

   LONG   GetWakeTime(VOID)        { return lWakeTime; }
   VOID   SetWakeTime(LONG lParm)  { lWakeTime = lParm; }

   BOOL   GetfCritical(VOID)       { return fCritical; }
   VOID   SetfCritical(BOOL fParm) { fCritical = fParm; }

   SHORT  GetPrevState(VOID)       { return sPrevState; }
   VOID   SetPrevState(SHORT sParm){ sPrevState = sParm; }

   BOOL   GetStateChanged(VOID)    { return fStateChanged; }
   VOID   SetStateChanged(BOOL fParm) { fStateChanged = fParm; }

   PVOID  GetWorkArea(VOID)        { return pvWorkArea; }
   VOID   SetWorkArea(PVOID pvParm){ pvWorkArea = pvParm; }


   //  
   // pProc and pBlocked SHOULD be private.  But compiler problems
   // with the function pointer types have caused them to be public
   // for direct access in this implementation
   //

   SHORT  (*pProc)(MOS_C *, PVOID);        // address of function which is the process
   SHORT  (*pBlockedFunc)(MOS_C *, PVOID); // address of blocked function 

   //  VOID   GetBlockedFunc(SHORT (**) (MOS_C *, PVOID));
   //  VOID   SetBlockedFunc(SHORT (*)(MOS_C * ,PVOID));
   //  VOID   GetProc(SHORT (**) (MOS_C *,PVOID));
   //  VOID   SetProc(SHORT (*)(MOS_C *,PVOID));

   CHAR     szProcStates[PROC_STATE_MSG_WAIT + 1][32];

   QUEUE_C  clMsgQue;  // message queue for incoming messages

};


typedef PROC_C * PROC_P;



//
//  Event Class
//

struct EVENT_S
{
   SHORT  (*pCheckFunc)(VOID);  /* function to check for event */
   PROC_P pclEventProc;         /* process awaiting event */
};

typedef struct EVENT_S EVENT_T;
typedef EVENT_T * EVENT_P;




//
//  MOS Class
//  


class MOS_C
{

private:

   #define  MOS_NULL_PROC_PRIO 0
   #define  MOS_SEM_SET        1

   //
   //   There can only be one currently running process
   //   All application requests are resolved as belonging to 
   //   this process
   //

   PROC_P   pclRunProc;

   //
   //    Use a binary tree to track all processes
   //

   TREE_C   clProcTree;

   LLIST_C  clPidList;

   //
   //   The Ready Queue is ordered by priority so it is a heap
   //
   
   HEAP_C   clQueReady;

   //
   //    The Msg Wait Queue is ordered by priority.  But since we cant predict
   //    the order of events which waiting processes are waiting for, we
   //    will make it a linked-list for maximum flexibility.
   //

   LLIST_C  clQueMsgWait;

   LLIST_C  clQueSleep;

   //
   //  The infamous NULL process
   //
 
   // SHORT  NullProc(MOS_C * pclMos,PVOID);

   SHORT  ReschedReady(PROC_P pclProc);
   SHORT  GetReadyProc(PROC_P * ppclProc);
   SHORT  CheckSleepQueue(VOID);


   LONG	  lNumProcs;

   SHORT  sProcId; 

   // Semaphores

   SHORT  sSemHandle;

   LLIST_C  clSemList;

   VOID   SemFindHandle(SEM_HANDLE, SEM_P *, BOOL *);
   VOID   SemNextProc(SEM_P);

   // Events
   SHORT  sEvents;
   LLIST_C  pclEventList;

   SHORT  EventCheckList(VOID);


   SHORT  Init(VOID);


public:

   MOS_C(VOID) {Init();};
   ~MOS_C(VOID) {};

   //
   //  Standard operating system 'core' functions
   //

   //  Proc create parms are:  function, name, priority, workarea
   SHORT  ProcCreate(SHORT (*)(MOS_C *,PVOID), PCHAR, SHORT, PVOID);
   SHORT  ProcTerm(VOID);

   SHORT  Scheduler(VOID);

   SHORT  Sleep(LONG);     // secs to sleep

   VOID   SetBlockedFunc(SHORT (*)(MOS_C *,PVOID));


   // Semaphore service functions

   SHORT  SemInit(PCHAR);         // returns handle, ok if two procs init
   SHORT  SemTerm(SEM_HANDLE);
   SHORT  SemWait(SEM_HANDLE);
   SHORT  SemSignal(SEM_HANDLE);
   SHORT  SemClear(SEM_HANDLE);
   SHORT  SemSet(SEM_HANDLE);

   // Messaging service functions

   BOOL   MsgWaiting(VOID);
   SHORT  MsgWrite(MSG_C *);   // parm is target proc, see GetPidByName
   SHORT  MsgRead(MSG_C *);

   SHORT  GetPidByName(PCHAR);
  
   LONG   GetTime(VOID);

   //
   //  A user notification function
   //

   SHORT  ProcAnnounce(VOID);

};

typedef MOS_C * MOS_P;


SHORT
MosNullProc(MOS_P pclMos,PVOID pvWorkArea);



//
//  Compare functions, called by memlib tree and linked list routines
//  for searching/deleting
//

SHORT  MosCompareProcId(PVOID,PVOID);
SHORT  MosCompareIdNode(PVOID,PVOID);
SHORT  MosCompareProcName(PVOID,PVOID);
SHORT  CompareProcWakeTime(PVOID,PVOID);

#endif




⌨️ 快捷键说明

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