[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Minios-devel] [UNIKRAFT PATCH] lib/ukmpi: Fix locking of semaphores when using timeouts for mailboxes
Recently, uk_semaphore_down_to call was changed to be inline with its POSIX counterpart. This means that when timeout value is 0, the call returns immediately and behaves like a try lock operation. POSIX passed the timeout parameter as a pointer and if the pointer was NULL the function blocked "forever", an approach we cannot use because our timeout parameter is passed by value. Therefore, we had to update all the semaphores locking calls to use uk_semaphore_down when timeout was set to 0 by the caller. Signed-off-by: Costin Lupu <costin.lupu@xxxxxxxxx> --- lib/ukmpi/mbox.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/lib/ukmpi/mbox.c b/lib/ukmpi/mbox.c index 3a0354dd..31acdc6d 100644 --- a/lib/ukmpi/mbox.c +++ b/lib/ukmpi/mbox.c @@ -100,9 +100,17 @@ __nsec uk_mbox_post_to(struct uk_mbox *m, void *msg, __nsec timeout) UK_ASSERT(m); - ret = uk_semaphore_down_to(&m->writesem, timeout); - if (ret != __NSEC_MAX) + if (timeout) { + ret = uk_semaphore_down_to(&m->writesem, timeout); + if (ret != __NSEC_MAX) + _do_mbox_post(m, msg); + } else { + /* no timeout, we wait forever */ + uk_semaphore_down(&m->readsem); _do_mbox_post(m, msg); + ret = 0; + } + return ret; } @@ -172,9 +180,16 @@ __nsec uk_mbox_recv_to(struct uk_mbox *m, void **msg, __nsec timeout) UK_ASSERT(m); - ret = uk_semaphore_down_to(&m->readsem, timeout); - if (ret != __NSEC_MAX) + if (timeout) { + ret = uk_semaphore_down_to(&m->readsem, timeout); + if (ret != __NSEC_MAX) + rmsg = _do_mbox_recv(m); + } else { + /* no timeout, we wait forever */ + uk_semaphore_down(&m->readsem); rmsg = _do_mbox_recv(m); + ret = 0; + } if (msg) *msg = rmsg; -- 2.11.0 _______________________________________________ Minios-devel mailing list Minios-devel@xxxxxxxxxxxxxxxxxxxx https://lists.xenproject.org/mailman/listinfo/minios-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |