<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">
From: Manfred Spraul &lt;manfred@colorfullife.com&gt;

Linux specific extension: make the message queue identifiers pollable.  It's
simple and could be useful.


---

 25-akpm/ipc/mqueue.c |   27 ++++++++++++++++++++++++---
 1 files changed, 24 insertions(+), 3 deletions(-)

diff -puN ipc/mqueue.c~mq-04-linuxext-poll ipc/mqueue.c
--- 25/ipc/mqueue.c~mq-04-linuxext-poll	2004-04-03 02:59:53.424231224 -0800
+++ 25-akpm/ipc/mqueue.c	2004-04-03 02:59:53.428230616 -0800
@@ -251,6 +251,24 @@ static int mqueue_flush_file(struct file
 	return 0;
 }
 
+static unsigned int mqueue_poll_file(struct file *filp, struct poll_table_struct *poll_tab)
+{
+	struct mqueue_inode_info *info = MQUEUE_I(filp-&gt;f_dentry-&gt;d_inode);
+	int retval = 0;
+
+	poll_wait(filp, &amp;info-&gt;wait_q, poll_tab);
+
+	spin_lock(&amp;info-&gt;lock);
+	if (info-&gt;attr.mq_curmsgs)
+		retval = POLLIN | POLLRDNORM;
+
+	if (info-&gt;attr.mq_curmsgs &lt; info-&gt;attr.mq_maxmsg)
+		retval |= POLLOUT | POLLWRNORM;
+	spin_unlock(&amp;info-&gt;lock);
+
+	return retval;
+}
+
 /* Adds current to info-&gt;e_wait_q[sr] before element with smaller prio */
 static void wq_add(struct mqueue_inode_info *info, int sr,
 			struct ext_wait_queue *ewp)
@@ -376,11 +394,11 @@ static void __do_notify(struct mqueue_in
 				       &amp;sig_i, info-&gt;notify_owner);
 		} else if (info-&gt;notify.sigev_notify == SIGEV_THREAD) {
 			info-&gt;notify_filp-&gt;private_data = (void*)NP_WOKENUP;
-			wake_up(&amp;info-&gt;wait_q);
 		}
 		/* after notification unregisters process */
 		info-&gt;notify_owner = 0;
 	}
+	wake_up(&amp;info-&gt;wait_q);
 }
 
 static long prepare_timeout(const struct timespec __user *u_arg)
@@ -712,9 +730,11 @@ static inline void pipelined_receive(str
 {
 	struct ext_wait_queue *sender = wq_get_first_waiter(info, SEND);
 
-	if (!sender)
+	if (!sender) {
+		/* for poll */
+		wake_up_interruptible(&amp;info-&gt;wait_q);
 		return;
-
+	}
 	msg_insert(sender-&gt;msg, info);
 	list_del(&amp;sender-&gt;list);
 	sender-&gt;state = STATE_PENDING;
@@ -1035,6 +1055,7 @@ static struct inode_operations mqueue_di
 
 static struct file_operations mqueue_file_operations = {
 	.flush = mqueue_flush_file,
+	.poll = mqueue_poll_file,
 };
 
 static struct file_operations mqueue_notify_fops = {

_
</pre></body></html>