From dfd71f419d02f1f139ab614a88393aaab53654e5 Mon Sep 17 00:00:00 2001 From: Giovanni Di Sirio Date: Sat, 6 Feb 2016 10:31:02 +0000 Subject: Fixed bug #696. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@8825 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/various/lwip_bindings/arch/sys_arch.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'os') diff --git a/os/various/lwip_bindings/arch/sys_arch.c b/os/various/lwip_bindings/arch/sys_arch.c index 6107de252..950213ef1 100644 --- a/os/various/lwip_bindings/arch/sys_arch.c +++ b/os/various/lwip_bindings/arch/sys_arch.c @@ -99,18 +99,18 @@ void sys_sem_signal_S(sys_sem_t *sem) { } u32_t sys_arch_sem_wait(sys_sem_t *sem, u32_t timeout) { - systime_t tmo; - u32_t time; + systime_t tmo, start, remaining; osalSysLock(); tmo = timeout > 0 ? MS2ST((systime_t)timeout) : TIME_INFINITE; - time = (u32_t)ST2MS(osalOsGetSystemTimeX()); - if (chSemWaitTimeoutS(*sem, tmo) != MSG_OK) - time = SYS_ARCH_TIMEOUT; - else - time = (u32_t)ST2MS(osalOsGetSystemTimeX()) - time; + start = osalOsGetSystemTimeX(); + if (chSemWaitTimeoutS(*sem, tmo) != MSG_OK) { + osalSysUnlock(); + return SYS_ARCH_TIMEOUT; + } + remaining = osalOsGetSystemTimeX() - start; osalSysUnlock(); - return time; + return (u32_t)ST2MS(remaining); } int sys_sem_valid(sys_sem_t *sem) { @@ -171,18 +171,18 @@ err_t sys_mbox_trypost(sys_mbox_t *mbox, void *msg) { } u32_t sys_arch_mbox_fetch(sys_mbox_t *mbox, void **msg, u32_t timeout) { - u32_t time; - systime_t tmo; + systime_t tmo, start, remaining; osalSysLock(); tmo = timeout > 0 ? MS2ST((systime_t)timeout) : TIME_INFINITE; - time = (u32_t)osalOsGetSystemTimeX(); - if (chMBFetchS(*mbox, (msg_t *)msg, tmo) != MSG_OK) - time = SYS_ARCH_TIMEOUT; - else - time = (u32_t)ST2MS(osalOsGetSystemTimeX()) - time; + start = osalOsGetSystemTimeX(); + if (chMBFetchS(*mbox, (msg_t *)msg, tmo) != MSG_OK) { + osalSysUnlock(); + return SYS_ARCH_TIMEOUT; + } + remaining = osalOsGetSystemTimeX() - start; osalSysUnlock(); - return time; + return (u32_t)ST2MS(remaining); } u32_t sys_arch_mbox_tryfetch(sys_mbox_t *mbox, void **msg) { -- cgit v1.2.3