From: lottaviano Date: Fri, 5 Aug 2011 09:50:51 +0000 (+0000) Subject: Fixes to lwIP implementation from external projects. X-Git-Tag: 2.7.0~5 X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=e3e3ddfc434c148bcb55ce78dc496d267a1ab2b2;p=bertos.git Fixes to lwIP implementation from external projects. "Mailboxes can be created in a different process than the one that waits for messages. This is a problem with BeRTOS MsgPorts because the process to be woken up is set during init. In this patch, the process to be awaken is changed just before waiting. Fix compilation warnings." git-svn-id: https://src.develer.com/svnoss/bertos/branches/2.7@4994 38d2e660-2303-0410-9eaa-f027e97ec537 --- diff --git a/bertos/net/lwip/src/arch/sys_arch.c b/bertos/net/lwip/src/arch/sys_arch.c index d626f0cf..b883529c 100644 --- a/bertos/net/lwip/src/arch/sys_arch.c +++ b/bertos/net/lwip/src/arch/sys_arch.c @@ -1,7 +1,7 @@ #include "cfg/cfg_lwip.h" -#define LOG_LEVEL 3 -#define LOG_FORMAT 0 +#define LOG_LEVEL 3 //INFO +#define LOG_FORMAT 0 //TERSE #include #include @@ -153,6 +153,7 @@ u32_t sys_arch_sem_wait(sys_sem_t sem, u32_t timeout) mutex_obtain(sem); return ticks_to_ms(timer_clock() - start); } + do { cpu_relax(); @@ -197,6 +198,7 @@ sys_mbox_t sys_mbox_new(UNUSED_ARG(int, size)) return SYS_MBOX_NULL; } msg_initPort(&port->port, event_createGeneric()); + port->port.event.Ev.Sig.sig_proc = NULL; return (sys_mbox_t)(&port->port); } @@ -209,8 +211,7 @@ void sys_mbox_free(sys_mbox_t mbox) void sys_mbox_post(sys_mbox_t mbox, void *data) { - if (UNLIKELY(sys_mbox_trypost(mbox, data) == ERR_MEM)) - LOG_ERR("out of messages!\n"); + sys_mbox_trypost(mbox, data); } /* @@ -223,9 +224,18 @@ err_t sys_mbox_trypost(sys_mbox_t mbox, void *data) PROC_ATOMIC(msg = (IpMsg *)list_remHead(&free_msg)); if (UNLIKELY(!msg)) + { + LOG_ERR("out of messages!\n"); return ERR_MEM; + } msg->data = data; - msg_put(mbox, &msg->msg); + + msg_lockPort(mbox); + ADDTAIL(&mbox->queue, &msg->msg.link); + msg_unlockPort(mbox); + + if (mbox->event.Ev.Sig.sig_proc) + event_do(&mbox->event); return ERR_OK; } @@ -257,13 +267,22 @@ u32_t sys_arch_mbox_fetch(sys_mbox_t mbox, void **data, u32_t timeout) msg = msg_get(mbox); if (LIKELY(msg)) break; + + mbox->event.Ev.Sig.sig_proc = proc_current(); /* Slow path */ if (!timeout) event_wait(&mbox->event); - else if (!event_waitTimeout(&mbox->event, + else + { + if (!event_waitTimeout(&mbox->event, ms_to_ticks(timeout))) - return SYS_ARCH_TIMEOUT; + { + mbox->event.Ev.Sig.sig_proc = NULL; + return SYS_ARCH_TIMEOUT; + } + } } + mbox->event.Ev.Sig.sig_proc = NULL; if (data) *data = containerof(msg, IpMsg, msg)->data; @@ -317,6 +336,15 @@ static struct sys_timeouts lwip_system_timeouts; // Default timeouts list for lw struct sys_timeouts *sys_arch_timeouts(void) { + ThreadNode *thread_node; + struct Process *curr_pid = proc_current(); + + FOREACH_NODE(thread_node, &used_thread) + { + if (thread_node->pid == curr_pid) + return &(thread_node->timeout); + } + return &lwip_system_timeouts; } @@ -350,6 +378,7 @@ sys_thread_t sys_thread_new(const char *name, void (* thread)(void *arg), if (UNLIKELY(!thread_node)) { proc_permit(); + LOG_ERR("Out of threads!\n"); return NULL; } ADDHEAD(&used_thread, &thread_node->node); @@ -360,7 +389,7 @@ sys_thread_t sys_thread_new(const char *name, void (* thread)(void *arg), #if !CONFIG_KERN_HEAP ASSERT(stacksize <= DEFAULT_THREAD_STACKSIZE); - PROC_ATOMIC(stackbase = &thread_stack[last_stack++]); + PROC_ATOMIC(stackbase = thread_stack[last_stack++]); #else stackbase = NULL; #endif