Please wait until the page is fully downloaded and then press the "Expand" button or the blue line numbers.

0011001 /*
0011002 inet/mq.c
0011003 
0011004 Created:       Jan 3, 1992 by Philip Homburg
0011005 
0011006 Copyright 1995 Philip Homburg
0011007 */
mq_list / mq_freelist / mq_init() / mq_get() / mq_free()

Messages that the network service receives from the other services (file system, memory manager, etc.) and the kernel are placed into a linked list. This linked list is formed with the following struct:

typedef struct mq

{
message mq_mess;
struct mq *mq_next;
int mq_allocated;
} mq_t;
and is initialized by mq_init(). After initialization, the linked list is as follows:



As messages are received, mq_get() is called to acquire the element of mq_list[] pointed to by mq_freelist. This element holds the message until the message is processed. mq_allocated for this element is set to 1 and mq_freelist is advanced to point to the next element.

After the message is processed, mq_free() places the element back onto mq_freelist and sets mq_allocated back to 0.

As with other queues within the network service, the memory for the message queue comes from an array with a limited number of elements. This must be done because memory within Minix is scarce (for one reason, Minix does not have virtual memory).

Click here for a description of the different types of messages.


0011008 
0011009 #include "inet.h"
0011010 #include "mq.h"
0011011 #include "generic/assert.h"
0011012 
0011013 THIS_FILE
0011014 
0011015 #define MQ_SIZE              128
0011016 
0011017 PRIVATE mq_t mq_list[MQ_SIZE];
0011018 PRIVATE mq_t *mq_freelist;
0011019 
0011020 void mq_init()
mq_init()

mq_init() initializes mq_list[] and mq_freelist as follows:



Click here for a detailed description of mq_list[] and mq_freelist.mq_init()

mq_init() initializes mq_list[] and mq_freelist as follows:



Click here for a detailed description of mq_list[] and mq_freelist.mq_init()

mq_init() initializes mq_list[] and mq_freelist as follows:



Click here for a detailed description of mq_list[] and mq_freelist.

Participant comment / Author: Andy Swartzbaugh / Date of Posting: 2005-08-29

This is a test comment.


Participant comment / Author: / Date of Posting: 2005-08-29

This is ' another test comment.


Participant comment / Author: Andy 2 / Date of Posting: 2005-08-29

This is " another test comment.



0011021 {
0011022          int i;
0011023 
0011024          mq_freelist= NULL;
0011025          for (i= 0; i<MQ_SIZE; i++)
0011026          {
0011027                   mq_list[i].mq_next= mq_freelist;
0011028                   mq_freelist= &mq_list[i];
0011029                   mq_list[i].mq_allocated= 0;
0011030          }
0011031 }
0011032 
0011033 mq_t *mq_get()
mq_get()

mq_get() returns a pointer to the next available element of mq_list[] on mq_freelist.



Click here for a detailed description of mq_list[] and mq_freelist.


0011034 {
0011035          mq_t *mq;
0011036 
0011037          mq= mq_freelist;
0011038          assert(mq != NULL);
0011039 
0011040          mq_freelist= mq->mq_next;
0011041          mq->mq_next= NULL;
0011042          assert(mq->mq_allocated == 0);
0011043          mq->mq_allocated= 1;
0011044          return mq;
0011045 }
0011046 
0011047 void mq_free(mq)
0011048 mq_t *mq;
mq_free()

mq_free(mq) places mq, mq_free()'s only parameter, back on mq_freelist.



Click here for a detailed description of mq_list[] and mq_freelist.


0011049 {
0011050          mq->mq_next= mq_freelist;
0011051          mq_freelist= mq;
0011052          assert(mq->mq_allocated == 1);
0011053          mq->mq_allocated= 0;
0011054 }
0011055 
0011056 /*
0011057  * $PchId: mq.c,v 1.6 1996/05/07 21:10:16 philip Exp $
0011058  */