#include "cfg/cfg_lwip.h"
-#define LOG_LEVEL 3
-#define LOG_FORMAT 0
+#define LOG_LEVEL 3 //INFO
+#define LOG_FORMAT 0 //TERSE
#include <cfg/log.h>
#include <drv/timer.h>
mutex_obtain(sem);
return ticks_to_ms(timer_clock() - start);
}
+
do
{
cpu_relax();
return SYS_MBOX_NULL;
}
msg_initPort(&port->port, event_createGeneric());
+ port->port.event.Ev.Sig.sig_proc = NULL;
return (sys_mbox_t)(&port->port);
}
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);
}
/*
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;
}
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;
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;
}
if (UNLIKELY(!thread_node))
{
proc_permit();
+ LOG_ERR("Out of threads!\n");
return NULL;
}
ADDHEAD(&used_thread, &thread_node->node);
#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