[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Minios-devel] [UNIKRAFT PATCH] lib/ukmpi: Provide blocking uk_mbox_recv()



Commit a48d634 ("lib/uklock: Use timeout equal to 0 for trying down a
semaphore") implicitly changed the behavior of `uk_mbox_recv_to()`. When
passing timeout `0`, the function is not blocking until a message
arrives but trying to receive a message and returning immediately.

This patch introduces `uk_mbox_recv()` which brings back this blocking
behavior. I chose introducing this new function in order to keep the
mailbox API inline with the semaphore ones.

Signed-off-by: Simon Kuenzer <simon.kuenzer@xxxxxxxxx>
---
 lib/ukmpi/exportsyms.uk     |  1 +
 lib/ukmpi/include/uk/mbox.h |  1 +
 lib/ukmpi/mbox.c            | 17 +++++++++++++++++
 3 files changed, 19 insertions(+)

diff --git a/lib/ukmpi/exportsyms.uk b/lib/ukmpi/exportsyms.uk
index 4c4c8874..b0d661a0 100644
--- a/lib/ukmpi/exportsyms.uk
+++ b/lib/ukmpi/exportsyms.uk
@@ -3,5 +3,6 @@ uk_mbox_free
 uk_mbox_post
 uk_mbox_post_try
 uk_mbox_post_to
+uk_mbox_recv
 uk_mbox_recv_try
 uk_mbox_recv_to
diff --git a/lib/ukmpi/include/uk/mbox.h b/lib/ukmpi/include/uk/mbox.h
index d2c48e53..19b1ecc0 100644
--- a/lib/ukmpi/include/uk/mbox.h
+++ b/lib/ukmpi/include/uk/mbox.h
@@ -56,6 +56,7 @@ void uk_mbox_post(struct uk_mbox *m, void *msg);
 int uk_mbox_post_try(struct uk_mbox *m, void *msg);
 __nsec uk_mbox_post_to(struct uk_mbox *m, void *msg, __nsec timeout);
 
+void uk_mbox_recv(struct uk_mbox *m, void **msg);
 int uk_mbox_recv_try(struct uk_mbox *m, void **msg);
 __nsec uk_mbox_recv_to(struct uk_mbox *m, void **msg, __nsec timeout);
 
diff --git a/lib/ukmpi/mbox.c b/lib/ukmpi/mbox.c
index 3a0354dd..149a667d 100644
--- a/lib/ukmpi/mbox.c
+++ b/lib/ukmpi/mbox.c
@@ -127,6 +127,23 @@ static inline void *_do_mbox_recv(struct uk_mbox *m)
        return ret;
 }
 
+/* Blocks the thread until a message arrives in the mailbox.
+ * The `*msg` argument will point to the received message.
+ * If the `msg` parameter was set to NULL, the received message is dropped.
+ */
+void uk_mbox_recv(struct uk_mbox *m, void **msg)
+{
+       void *rmsg;
+
+       UK_ASSERT(m);
+
+       uk_semaphore_down(&m->readsem);
+       rmsg =  _do_mbox_recv(m);
+       if (msg)
+               *msg = rmsg;
+}
+
+
 /* This is similar to uk_mbox_fetch, however if a message is not
  * present in the mailbox, it immediately returns with the code
  * SYS_MBOX_EMPTY. On success 0 is returned.
-- 
2.21.0


_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/minios-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.