POSIX message queues

POSIX message queues implement priority-ordered messages. Each message written by a sender process is associated with an integer number which is interpreted as message priority; messages with a higher number are considered higher in priority. The message queue orders current messages as per priority and delivers them to the reader process in descending order (highest priority first). This implementation also supports a wider API interface with facilities of bounded wait send and receive operations and asynchronous message arrival notifications for receivers through signals or threads.

This implementation provides a distinct API interface to create, open, read, write, and destroy message queues. Following is a summarized description of APIs (we will not discuss usage semantics here, refer to system programming manuals for more details):

API interface Description
mq_open() Create or open a POSIX message queue
mq_send() Write a message to the queue
mq_timedsend() Similar to mq_send, but with a timeout parameter for bounded operations
mq_receive() Fetch a message from the queue; this operation is possible on unbounded blocking calls
mq_timedreceive() Similar to mq_receive() but with a timeout parameter that limits possible blocking for bounded time
mq_close() Close a message queue
mq_unlink() Destroy message queue
mq_notify() Customize and set up message arrival notifications
mq_getattr() Get attributes associated with a message queue
mq_setattr() Set attributes specified on a message queue

 

POSIX message queues are managed by a special filesystem called mqueue. Each message queue is identified by a filename. Metadata for each queue is described by an instance of struct mqueue_inode_info, which symbolizes the inode object associated with the message queue file in the mqueue filesystem:

struct mqueue_inode_info {
spinlock_t lock;
struct inode vfs_inode;
wait_queue_head_t wait_q;

struct rb_root msg_tree;
struct posix_msg_tree_node *node_cache;
struct mq_attr attr;

struct sigevent notify;
struct pid *notify_owner;
struct user_namespace *notify_user_ns;
struct user_struct *user; /* user who created, for accounting */
struct sock *notify_sock;
struct sk_buff *notify_cookie;

/* for tasks waiting for free space and messages, respectively */
struct ext_wait_queue e_wait_q[2];

unsigned long qsize; /* size of queue in memory (sum of all msgs) */
};

The *node_cache pointer refers to the posix_msg_tree_node descriptor that contains the header to a linked list of message nodes, in which each message is represented by a descriptor of type msg_msg:

 
struct posix_msg_tree_node {
struct rb_node rb_node;
struct list_head msg_list;
int priority;
};
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.141.24.134