sys.h, sys.c, api_lib.c, tcpip.c: remove sys_mbox_fetch_timeout() (was only used for LWIP_SO_RCVTIMEO option) and use sys_arch_mbox_fetch() instead of sys_mbox_fetch() in api files. Now, users SHOULD NOT use internal lwIP features like "sys_timeout" in their application threads.

This commit is contained in:
fbernon 2007-05-22 20:51:34 +00:00
parent 0aaf69769f
commit 2ff620e1b5
5 changed files with 18 additions and 62 deletions

View File

@ -10,10 +10,6 @@ FUTURE
(sizeof(int)). In ppp.c an assumption is made on the availability of
a thread subsystem. Either PPP needs to be moved to contrib/ports/???
or rearranged to be more generic.
* TODO: review the the sequential netconn and socket API (lwip/src/api)
for bugs and performance issues. Frequent system calls (e.g. sys_mbox_fetch)
slooow things down considerably.
HISTORY
@ -170,6 +166,12 @@ HISTORY
* tcp.c: Fixed bug #1895 (tcp_bind not correct) by introducing a list of
bound but unconnected (and non-listening) tcp_pcbs.
2007-05-22 Frédéric Bernon
* sys.h, sys.c, api_lib.c, tcpip.c: remove sys_mbox_fetch_timeout() (was only
used for LWIP_SO_RCVTIMEO option) and use sys_arch_mbox_fetch() instead of
sys_mbox_fetch() in api files. Now, users SHOULD NOT use internal lwIP features
like "sys_timeout" in their application threads.
2007-05-22 Frédéric Bernon
* api.h, api_lib.c, api_msg.h, api_msg.c: change the struct api_msg_msg to see
which parameters are used by which do_xxx function, and to avoid "misusing"

View File

@ -443,7 +443,7 @@ netconn_accept(struct netconn *conn)
return NULL;
}
sys_mbox_fetch(conn->acceptmbox, (void *)&newconn);
sys_arch_mbox_fetch(conn->acceptmbox, (void *)&newconn, 0);
/* Register event with callback */
if (conn->callback)
(*conn->callback)(conn, NETCONN_EVT_RCVMINUS, 0);
@ -488,7 +488,7 @@ netconn_recv(struct netconn *conn)
return NULL;
}
sys_mbox_fetch(conn->recvmbox, (void *)&p);
sys_arch_mbox_fetch(conn->recvmbox, (void *)&p, 0);
if (p != NULL)
{
@ -529,9 +529,9 @@ netconn_recv(struct netconn *conn)
} else {
#if (LWIP_UDP || LWIP_RAW)
#if LWIP_SO_RCVTIMEO
sys_mbox_fetch_timeout(conn->recvmbox, (void *)&buf, conn->recv_timeout);
sys_arch_mbox_fetch(conn->recvmbox, (void *)&buf, conn->recv_timeout);
#else
sys_mbox_fetch(conn->recvmbox, (void *)&buf);
sys_arch_mbox_fetch(conn->recvmbox, (void *)&buf, 0);
#endif /* LWIP_SO_RCVTIMEO*/
if (buf!=NULL)
{ conn->recv_avail -= buf->p->tot_len;

View File

@ -321,7 +321,7 @@ tcpip_apimsg(struct api_msg *apimsg)
msg.type = TCPIP_MSG_API;
msg.msg.apimsg = apimsg;
sys_mbox_post(mbox, &msg);
sys_mbox_fetch(apimsg->msg.conn->mbox, NULL);
sys_arch_mbox_fetch(apimsg->msg.conn->mbox, NULL, 0);
return ERR_OK;
}
return ERR_VAL;
@ -333,17 +333,17 @@ err_t tcpip_netifapi(struct netifapi_msg* netifapimsg)
struct tcpip_msg msg;
if (mbox != SYS_MBOX_NULL) {
netifapimsg->sem = sys_sem_new(0);
netifapimsg->sem = sys_sem_new(0);
if (netifapimsg->sem == SYS_SEM_NULL) {
netifapimsg->err = ERR_MEM;
return netifapimsg->err;
}
}
msg.type = TCPIP_MSG_NETIFAPI;
msg.msg.netifapimsg = netifapimsg;
sys_mbox_post(mbox, &msg);
sys_sem_wait(netifapimsg->sem);
sys_sem_free(netifapimsg->sem);
sys_sem_free(netifapimsg->sem);
return netifapimsg->err;
}
return ERR_VAL;

View File

@ -44,11 +44,8 @@ struct sswt_cb
};
#if LWIP_SO_RCVTIMEO
void sys_mbox_fetch_timeout(sys_mbox_t mbox, void **msg, u32_t timeout)
#else
void sys_mbox_fetch(sys_mbox_t mbox, void **msg)
#endif /* LWIP_SO_RCVTIMEO */
void
sys_mbox_fetch(sys_mbox_t mbox, void **msg)
{
u32_t time;
struct sys_timeouts *timeouts;
@ -60,38 +57,15 @@ void sys_mbox_fetch(sys_mbox_t mbox, void **msg)
timeouts = sys_arch_timeouts();
if (!timeouts || !timeouts->next) {
#if LWIP_SO_RCVTIMEO
time = sys_arch_mbox_fetch(mbox, msg, timeout);
#else
time = sys_arch_mbox_fetch(mbox, msg, 0);
#endif /* LWIP_SO_RCVTIMEO */
} else {
if (timeouts->next->time > 0) {
#if LWIP_SO_RCVTIMEO
time = sys_arch_mbox_fetch(mbox, msg, (timeout?((timeout<timeouts->next->time)?timeout:timeouts->next->time):timeouts->next->time));
#else
time = sys_arch_mbox_fetch(mbox, msg, timeouts->next->time);
#endif /* LWIP_SO_RCVTIMEO */
} else {
time = SYS_ARCH_TIMEOUT;
}
if (time == SYS_ARCH_TIMEOUT) {
#if LWIP_SO_RCVTIMEO
if ((timeout) && (timeout<timeouts->next->time)) {
/* If time == SYS_ARCH_TIMEOUT, and we have wait "fetch's timeout" and not "timer's timeout",
The timeout variable is the number of milliseconds we have waited for the message. */
timeouts->next->time -= timeout;
} else {
/* The timeouts->next->time variable is the number of milliseconds we have waited for the message. */
if (timeouts->next->time < timeout) {
timeout -= timeouts->next->time;
} else {
/* either timeout == 0, or timeout must == timeouts->next->time */
if (timeout) timeout = SYS_ARCH_TIMEOUT;
}
#endif /* LWIP_SO_RCVTIMEO */
/* If time == SYS_ARCH_TIMEOUT, a timeout occured before a message
could be fetched. We should now call the timeout handler and
deallocate the memory allocated for the timeout. */
@ -104,16 +78,9 @@ void sys_mbox_fetch(sys_mbox_t mbox, void **msg)
LWIP_DEBUGF(SYS_DEBUG, ("smf calling h=%p(%p)\n", (void *)h, (void *)arg));
h(arg);
}
#if LWIP_SO_RCVTIMEO
if (timeout != SYS_ARCH_TIMEOUT)
#endif /* LWIP_SO_RCVTIMEO */
/* We try again to fetch a message from the mbox. */
goto again;
#if LWIP_SO_RCVTIMEO
}
#endif /* LWIP_SO_RCVTIMEO */
} else {
/* If time != SYS_ARCH_TIMEOUT, a message was received before the timeout
occured. The time variable is set to the number of
@ -124,14 +91,7 @@ void sys_mbox_fetch(sys_mbox_t mbox, void **msg)
timeouts->next->time = 0;
}
}
}
#if LWIP_SO_RCVTIMEO
if ((time == SYS_ARCH_TIMEOUT) && (msg))
{ (*msg)=NULL;
}
#endif /* LWIP_SO_RCVTIMEO */
}
void

View File

@ -58,7 +58,6 @@ struct sys_timeo {u8_t dummy;};
#define sys_arch_sem_wait(s,t)
#define sys_sem_free(s)
#define sys_mbox_new() 0
#define sys_mbox_fetch_timeout(m,d,t)
#define sys_mbox_fetch(m,d)
#define sys_mbox_post(m,d)
#define sys_mbox_free(m)
@ -132,12 +131,7 @@ u32_t sys_arch_mbox_tryfetch(sys_mbox_t mbox, void **msg);
/* For now, we map straight to sys_arch implementation. */
#define sys_mbox_tryfetch(mbox, msg) sys_arch_mbox_tryfetch(mbox, msg)
void sys_mbox_free(sys_mbox_t mbox);
#if LWIP_SO_RCVTIMEO
void sys_mbox_fetch_timeout(sys_mbox_t mbox, void **msg, u32_t timeout);
#define sys_mbox_fetch(m,d) sys_mbox_fetch_timeout(m,d,0)
#else
void sys_mbox_fetch(sys_mbox_t mbox, void **msg);
#endif /* LWIP_SO_RCVTIMEO */
/* Thread functions. */
sys_thread_t sys_thread_new(void (* thread)(void *arg), void *arg, int prio);