Title: 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.