home *** CD-ROM | disk | FTP | other *** search
-
- /* File: /u1/Eden/Kernel/MsgOps/fifoCode.c */
-
- /*
- * $Header: /u1/Eden/Kernel/MsgOps/RCS/fifoCode.v Revision 1.6 85/03/14 11:42:44 eric Exp$
- * INTERFACE: Defined by exported procedures.
- *
- * FUNCTION: Provides the Message Module FIFO Queue Services.
- *
- * IMPORTS: Eden/Kernel/MsgOps/Types.h,
- * /u1/Eden/ErrCodes/MMcodes.h,
- * /u1/Eden/Kernel/MsgOps/BufferTypes.h,
- * /u1/Eden/Kernel/MsgOps/FifoTypes.h.
- *
- * EXPORTS: MMInitQ, MMEnterInQ, MMGetFromQ, MMPurgeQ.
- *
- * DESIGN: FIFO queues are structured as linked lists where
- * entries are placed at the end of the queue and
- * removed from the head of the queue. Each queue
- * is of type FifoQueue containing a pointer to
- * the head and tail of the linked list. In addition,
- * the tail of the queue points back to the head.
- * Each queue entry contains the linkage to the entry
- * behind it in the queue, a search key, and two words
- * of caller-defined data. The search key allows
- * entries to be removed from the list out of order.
- *
- * $Log: /u1/Eden/Kernel/MsgOps/RCS/FifoCode.v $
- * Revision 1.6 85/03/14 11:42:44 eric
- * Slight mods to MXTraceMsg.
- *
- * Revision 1.5 83/03/19 11:42:44 cady
- * Modified to allow NULL data and key pointer parameters.
- *
- * Revision 1.4 83/02/25 12:15:45 cady
- * Added new trace levels.
- *
- * Revision 1.3 83/02/24 16:39:51 cady
- * Replaced conditional debug trace with dynamic trace.
- * Added conditional Kernel compilation.
- *
- * Revision 1.2 83/02/22 11:54:21 cady
- * Changed internal routines to be static.
- * Replaced #if Debug with #ifdef Debug.
- *
- * Revision 1.1 83/01/06 14:08:45 cady
- * Initial revision
- *
- * 4-Nov-1982 Initial implementation. S. Cady
- */
-
- /****************************************************************/
- /* */
- /* Message Module FIFO Queue Library */
- /* */
- /****************************************************************/
-
- #include "Kernel/h/mmCodes.h"
- #include "Kernel/h/mmBufTypes.h"
- #include "Kernel/h/mmFifoTypes.h"
- #include "Kernel/h/mmMsgTypes.h"
-
- /****************************************************************/
- /* */
- /* MMInitQ */
- /* */
- /* MMInitQ defines the specified FIFO queue to be empty. */
- /* */
- /****************************************************************/
-
- void MMInitQ( fQueue /* FIFO Queue */
- )
- register FifoQueue *fQueue;
- {
- MXTraceMsg(5, "MMInitQ( %d )\n", fQueue);
-
- fQueue->FifoHead = NULL;
- fQueue->FifoTail = NULL;
- }
-
- /****************************************************************/
- /* */
- /* MMEnterInQ */
- /* */
- /* MMEnterInQ creates an entry containing the specified search */
- /* key and data and inserts it at the end of the FIFO queue. */
- /* */
- /* Possible status codes: */
- /* MMSS_Success, MMSK_NoMem */
- /* */
- /****************************************************************/
-
- KKStatus MMEnterInQ( fQueue, /* FIFO Queue */
- fKey, /* Search Key */
- fData1, /* Entry Data */
- fData2
- )
- register FifoQueue *fQueue;
- UnsignedInteger fKey;
- integer fData1, fData2;
- {
- FifoEltPtr NewEntry;
- KKStatus status;
-
- MXTraceMsg(5, "MMEnterInQ( %d, %d, %d, %d )\n", fQueue,
- fKey, fData1, fData2);
-
- /* Allocate and initialize new queue element */
-
- status = MMAllocateData(sizeof(FifoElt), (char **) &NewEntry);
- if ( ! mSUCCESS(status) )
- return status;
- NewEntry->FifoKey = fKey;
- NewEntry->FifoData[0] = fData1;
- NewEntry->FifoData[1] = fData2;
-
- /* Insert new element at end of queue */
-
- if ( fQueue->FifoTail == NULL )
- { fQueue->FifoHead = NewEntry;
- NewEntry->FifoNext = NewEntry;
- }
- else
- { fQueue->FifoTail->FifoNext = NewEntry;
- NewEntry->FifoNext = fQueue->FifoHead;
- };
- fQueue->FifoTail = NewEntry;
- return MMSS_Success;
- }
-
- /****************************************************************/
- /* */
- /* MMGetFromQ */
- /* */
- /* MMGetFromQ removes the entry at the front of the queue and */
- /* returns the entry key and data. */
- /* */
- /* Possible status codes: */
- /* MMSS_Success, MMSF_NoEntry */
- /* */
- /****************************************************************/
-
- KKStatus MMGetFromQ( fQueue, /* FIFO Queue */
- fKey, /* Search Key */
- fData1, /* Entry Data */
- fData2
- )
- register FifoQueue *fQueue;
- UnsignedInteger *fKey;
- integer *fData1, *fData2;
- {
- register FifoEltPtr OldEntry;
-
- MXTraceMsg(5, "MMGetFromQ( %d )\n", fQueue);
-
- /* Get element at head of queue */
-
- if ( fQueue->FifoHead == NULL )
- return MMSF_NoEntry;
- OldEntry = fQueue->FifoHead;
- if ( fKey != NULL )
- *fKey = OldEntry->FifoKey;
- if ( fData1 != NULL )
- *fData1 = OldEntry->FifoData[0];
- if ( fData2 != NULL )
- *fData2 = OldEntry->FifoData[1];
-
- /* Remove from the queue */
-
- if ( fQueue->FifoTail == OldEntry )
- { fQueue->FifoHead = NULL;
- fQueue->FifoTail = NULL;
- }
- else
- { fQueue->FifoHead = OldEntry->FifoNext;
- fQueue->FifoTail->FifoNext = fQueue->FifoHead;
- };
-
- /* Deallocate old entry */
-
-
- MMDeallocateData((sizeof(FifoElt)), (char *) OldEntry);
-
- MXTraceMsg(5, "Dequeued: %d, %d, %d\n", *fKey, *fData1, *fData2);
-
- return MMSS_Success;
- }
-
- /****************************************************************/
- /* */
- /* MMPurgeQ */
- /* */
- /* MMPurgeQ searches the queue for an entry with the specified */
- /* key. If the key is found, the corresponding entry is */
- /* removed from the queue. If the key is not found, no action */
- /* is taken. */
- /* */
- /* Possible status codes: */
- /* MMSS_Success, MMSF_NoEntry. */
- /* */
- /****************************************************************/
-
- KKStatus MMPurgeQ( fQueue, /* FIFO Queue */
- fKey, /* Search Key */
- fData1, /* Entry Data */
- fData2
- )
- register FifoQueue *fQueue;
- UnsignedInteger fKey;
- integer *fData1, *fData2;
- {
- register FifoEltPtr Entry;
- register FifoEltPtr PrevEntry;
-
- MXTraceMsg(5, "MMPurgeQ( %d, %d )\n", fQueue, fKey);
-
- /* Search queue for matching entry */
-
- Entry = fQueue->FifoTail;
- if ( Entry != NULL )
- do {
- PrevEntry = Entry;
- Entry = Entry->FifoNext;
- if ( Entry->FifoKey == fKey )
- { /* Remove from queue and deallocate */
- if ( fQueue->FifoHead == fQueue->FifoTail )
- { fQueue->FifoHead = NULL;
- fQueue->FifoTail = NULL;
- }
- else
- { PrevEntry->FifoNext = Entry->FifoNext;
- if ( Entry == fQueue->FifoHead )
- fQueue->FifoHead = Entry->FifoNext;
- if ( Entry == fQueue->FifoTail )
- fQueue->FifoTail = PrevEntry;
- };
- if ( fData1 != NULL )
- *fData1 = Entry->FifoData[0];
- if ( fData2 != NULL )
- *fData2 = Entry->FifoData[1];
- MMDeallocateData((sizeof(FifoElt)), (char *) Entry);
- return MMSS_Success;
- }
- }
- while ( Entry != fQueue->FifoTail );
- return MMSF_NoEntry;
- }
- /****************************************************************/
- /* End of Message Module FIFO Queue Library */
- /****************************************************************/
-