lwip's semaphores are implemented based on semphores provided by
libuklock and lwip's mailboxes are implemented based on mailboxes
provided by libukmpi. The API of both have changed recently;
originally with commit
a48d634 ("lib/uklock: Use timeout equal to 0
for trying down a semaphore"): A passed timeout of `0` is now
immediately returning instead of blocking the current thread until the
according event happened.
This patch also depends on the Unikraft patch 734930 ("lib/ukmpi:
Provide blocking uk_mbox_recv()"):
https://patchwork.unikraft.org/patch/734930/
Signed-off-by: Simon Kuenzer <simon.kuenzer@neclab.eu>
Reviewed-by: Costin Lupu <costin.lupu@cs.pub.ro>
UK_ASSERT(sys_mbox_valid(mbox));
- nsret = uk_mbox_recv_to(mbox->mbox, msg,
- ukarch_time_msec_to_nsec((__nsec) timeout));
- if (unlikely(nsret == __NSEC_MAX))
- return SYS_ARCH_TIMEOUT;
+ if (timeout == 0) {
+ nsret = ukplat_monotonic_clock();
+ uk_mbox_recv(mbox->mbox, msg);
+ nsret = ukplat_monotonic_clock() - nsret;
+ } else {
+ nsret = uk_mbox_recv_to(mbox->mbox, msg,
+ ukarch_time_msec_to_nsec((__nsec)
+ timeout));
+ if (unlikely(nsret == __NSEC_MAX))
+ return SYS_ARCH_TIMEOUT;
+ }
return (u32_t) ukarch_time_nsec_to_msec(nsret);
}
{
__nsec nsret;
- nsret = uk_semaphore_down_to(&sem->sem,
- ukarch_time_msec_to_nsec((__nsec)
- timeout));
- if (unlikely(nsret == __NSEC_MAX))
- return SYS_ARCH_TIMEOUT;
+ uk_pr_debug("sys_arch_sem_wait(%p, %"PRIu32")\n", sem, timeout);
+ if (timeout == 0) {
+ nsret = ukplat_monotonic_clock();
+ uk_semaphore_down(&sem->sem);
+ nsret = ukplat_monotonic_clock() - nsret;
+ } else {
+ nsret = uk_semaphore_down_to(&sem->sem,
+ ukarch_time_msec_to_nsec((__nsec)
+ timeout));
+ if (unlikely(nsret == __NSEC_MAX))
+ return SYS_ARCH_TIMEOUT;
+ }
+
return (u32_t) ukarch_time_nsec_to_msec(nsret);
}