home *** CD-ROM | disk | FTP | other *** search
- /***********************************************************************
- **+
- ** Module Name: mos.h
- **
- ** Description: mos defines
- **
- ** Written by: John Tal
- **
- **
- ** Modification history:
- **
- ** Date Engineer Mod # Modification Description
- **
- ** 12-FEB-1992 Tal v 1.0-000 Initial release
- ** 25-APR-1992 Tal v 1.0-001 Event Handling
- **-
- ***********************************************************************/
-
-
- #ifdef MOS_H
- #else
- #define MOS_H
-
- #define MOS_ENVIRONMENT
-
- #include <memlib.h>
-
-
-
- /*
- ** Mos Include/define file
- */
-
-
-
- #define PROC_NAME_LEN 16
-
-
- /*
- ** An interprocess message
- */
-
- struct MSG_S
- {
- SHORT sSendPid;
- SHORT sDestPid;
- SHORT sLen;
- PCHAR pcData;
- };
-
- typedef struct MSG_S MSG_T;
- typedef MSG_T * MSG_P;
-
- #define MOS_NO_MSG -1
-
-
-
- #define SEM_NAME_LEN 16
-
- /*
- ** A semaphore
- */
-
- struct SEM_S
- {
- SHORT sVal;
- CHAR szSemName[SEM_NAME_LEN + 1];
- CHAR fInUse; /* being used, TRUE/FALSE */
- LLIST_P pstQueHead; /* processes waiting for this semaphore in queue */
- LLIST_P pstQueTail;
- };
-
- typedef struct SEM_S SEM_T;
- typedef SEM_T * SEM_P;
-
- #define MOS_MAX_SEMS 16
-
-
-
-
- /*
- ** A Process
- */
-
- struct PROC_S
- {
- CHAR szName[PROC_NAME_LEN + 1]; /* the process name */
- SHORT sProcId; /* the process id */
- SHORT sPriority; /* the process priority */
- SHORT sState; /* the process state */
- SHORT sPrevState; /* the previous state, for function */
- LLIST_P pstMsgQueHead; /* the process msg queue head */
- LLIST_P pstMsgQueTail; /* the process msg queue tail */
- LONG lWakeTime; /* time to wakeup process */
- BOOL fCritical; /* flag to prevent swapping */
- #ifdef C_ANSI
- SHORT (*pProc)(struct PROC_S *); /* address of main function which is the process */
- SHORT (*pBlockedFunc)(PVOID); /* address of current function which is in process */
- #else
- SHORT (*pProc)(); /* address of main function which is the process */
- SHORT (*pBlockedFunc)(); /* address of current function which is in process */
- #endif
- PVOID pvWorkArea;
- };
-
- typedef struct PROC_S PROC_T;
- typedef PROC_T * PROC_P;
-
-
- /*
- ** Process States
- */
-
- #define PROC_STATE_NO_EXIST -1
- #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
- #define PROC_STATE_EVT_WAIT 6
-
-
-
- /*
- ** An event
- ** The scheduler will check the event list by calling each check func
- ** when the return value from an event check func = TRUE, the
- ** EventFunc() is called. The EventFunc() is a limited-scope MOS
- ** process. All it should do send the appropriate message to whatever
- ** regular process(es) are waiting for its messag(es).
- ** When the pCheckFunc is true, the pstEvent proc is placed on the
- ** ready queue (event procs should be higher priority than regular
- ** procs). The event remains in the event list so the event proc should
- ** set its sState back to PROC_STATE_EVT_WAIT before exiting so it will not
- ** be placed back on the ready queue.
- **
- ** (Event procs are like VMS AST (asynchronus system traps)).
- */
-
- struct EVENT_S
- {
- #ifdef C_ANSI
- SHORT (*pCheckFunc)(VOID); /* function to check for event */
- #else
- SHORT (*pCheckFunc)(); /* function to check for event */
- #endif
- PROC_P pstEventProc; /* process awaiting event */
- };
-
- typedef struct EVENT_S EVENT_T;
- typedef EVENT_T * EVENT_P;
-
-
-
- #define MOS_EVENT_PROC_EXIT(pstProc) { (pstProc)->sState = PROC_STATE_EVT_WAIT; return (C_OK); }
-
-
-
- #define MOS_MAX_SEMS 16
-
-
-
-
-
-
-
-
- /*
- ** BLOCK_FUNC
- **
- ** The PROC_T member pBlockedFunc is provided for the scheduler to be able
- ** to restore a MOS process to a specific function within its call tree.
- **
- ** The scheduler will normally begin execution of a MOS process with the
- ** function which was initialized into pProc by MosProcCreate
- */
-
- #define MOS_SET_BLOCK_FUNC(Proc,Func) (Proc -> pBlockedFunc = Func)
- #define MOS_CLEAR_BLOCK_FUNC(Proc) (Proc -> pBlockedFunc = NULL)
-
-
- /*
- ** PROC WORK AREA
- **
- ** The proc work area is provided as a utility to each process.
- ** It is a void pointer that can point to anything which has meaning
- ** within functions of a process.
- */
-
- #define MOS_SET_PROC_WORK_AREA(Proc,WA) (Proc -> pvWorkArea = (PVOID) WA)
- #define MOS_GET_PROC_WORK_AREA(Proc) (Proc -> pvWorkArea)
-
- /* access to other MOS process members */
-
- #define MOS_SET_WAKE_TIME(Proc,time) (Proc -> lWakeTime = time)
- #define MOS_MSG_WAITING(Proc) ((Proc -> pstMsgQueHead != NULL) ? C_TRUE : C_FALSE)
-
-
- #define MOS_NUM_PROCS 4 /* for MosGenericProc, not normally used */
- #define MOS_NULL_PROC_PRIO 0 /* priority of Mos Null process */
- #define MOS_PROC_NULL -1 /* proc not running/found */
-
-
- /*
- ** SUSPENDED
- **
- ** Many MOS functions may not immediately complete for the current
- ** process (including MosSemWait, MosSleep, MosMsgRead). If any of
- ** these functions which can block return a suspended return code,
- ** your process must immediately do a C_LEAVE(C_OK) to return
- ** execution to the MOS scheduler
- */
-
- #define MOS_PROC_SUSPEND -2 /* signal for you to exit */
-
-
-
- #ifdef C_ANSI
- SHORT MosInit(VOID);
- SHORT MosTerm(VOID);
- SHORT MosScheduler(VOID);
- SHORT MosProcCreate(SHORT (*)(),PCHAR, SHORT);
- SHORT MosProcInit(SHORT (*)(),PCHAR, SHORT, PROC_P *);
- SHORT MosProcTerm(PROC_P);
- SHORT MosCheckSleepQueue(VOID);
- SHORT MosReschedReady(PROC_P);
- SHORT MosGetReadyProc(PROC_P *);
- SHORT MosGetPidByName(PCHAR,PSHORT);
- SHORT MosSemInit(PROC_P,PCHAR,PSHORT);
- SHORT MosSemTerm(PROC_P,PCHAR,SHORT);
- SHORT MosSemWait(PROC_P,SHORT);
- SHORT MosSemClear(PROC_P,SHORT);
- SHORT MosSemSet(PROC_P,SHORT);
- SHORT MosSemSignal(PROC_P,SHORT);
- SHORT MosEventCreate(SHORT (*)(VOID),SHORT (*)(PROC_P),PCHAR, SHORT);
- SHORT MosEventTerm(PROC_P);
- SHORT MosEventCheckList(VOID);
-
- #else
- SHORT MosInit();
- SHORT MosTerm();
- SHORT MosScheduler();
- SHORT MosProcCreate();
- SHORT MosProcInit();
- SHORT MosProcTerm();
- SHORT MosCheckSleepQueue();
- SHORT MosReschedReady();
- SHORT MosGetReadyProc();
- SHORT MosGetPidByName();
- SHORT MosSemInit();
- SHORT MosSemTerm();
- SHORT MosSemWait();
- SHORT MosSemClear();
- SHORT MosSemSet();
- SHORT MosSemSignal();
- SHORT MosEventCreate();
- SHORT MosEventTerm();
- SHORT MosEventCheckList();
- #endif
- /*
- ** Mos Function Prototypes
- */
-
-
- /*
- ** The infamous NULL process
- */
-
- #ifdef C_ANSI
- SHORT MosNullProc(PROC_P pstProc);
- #else
- SHORT MosNullProc();
- #endif
-
-
- /*
- ** A user notification function
- */
-
- #ifdef C_ANSI
- SHORT MosProcAnnounce(PROC_P pstProc);
- #else
- SHORT MosProcAnnounce();
- #endif
-
- /*
- ** Semaphore handlers
- */
-
- #ifdef C_ANSI
- SHORT MosSemWait(PROC_P pstProc,SHORT sSemHandle);
- SHORT MosSemSignal(PROC_P pstProc,SHORT sSemHandle);
- #else
- SHORT MosSemWait();
- SHORT MosSemSignal();
- #endif
-
- /*
- ** Time functions for process sleeping
- */
-
- #ifdef C_ANSI
- LONG MosCurTime(VOID);
- SHORT MosSleep(PROC_P pstProc);
- #else
- LONG MosCurTime();
- SHORT MosSleep();
- #endif
-
- /*
- ** Compare functions, called by memlib tree and linked list routines
- ** for searching/deleting
- */
-
- #ifdef C_ANSI
- SHORT MosCompareTime(PVOID pvData1,PVOID pvData2);
- SHORT MosCompareTreProcId(PVOID pvData1,PVOID pvData2);
- SHORT MosCompareIdNode(PVOID pvData1,PVOID pvData2);
- SHORT MosCompareTreProcName(PVOID pvData1,PVOID pvData2);
- #else
- SHORT MosCompareTime();
- SHORT MosCompareTreProcId();
- SHORT MosCompareIdNode();
- SHORT MosCompareIdNode();
- #endif
-
- /*
- ** Inter-process messaging
- */
-
- #ifdef C_ANSI
- SHORT MosMsgWrite(PROC_P pstProc,PCHAR pcData, SHORT sLen, SHORT sTargetProcId);
- SHORT MosMsgRead(PROC_P pstProc, MSG_P * ppcMsgBuf);
- SHORT MosTellMsgRead(PROC_P pstProc,PCHAR pcMsgBuf);
- #else
- SHORT MosMsgWrite();
- SHORT MosMsgRead();
- SHORT MosTellMsgRead();
- #endif
-
-
-
- #endif
-
-