mirror of
https://git.savannah.nongnu.org/git/lwip.git
synced 2025-08-04 13:34:38 +08:00
tcpip.c: Implement an easier way for TCPIP API calls - client code does not have to deal with semaphores and core locking any more
This commit is contained in:
parent
5e472badf1
commit
8106413644
@ -103,6 +103,11 @@ tcpip_thread(void *arg)
|
|||||||
LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: API message %p\n", (void *)msg));
|
LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: API message %p\n", (void *)msg));
|
||||||
msg->msg.api.function(msg->msg.api.msg);
|
msg->msg.api.function(msg->msg.api.msg);
|
||||||
break;
|
break;
|
||||||
|
case TCPIP_MSG_API_CALL:
|
||||||
|
LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: API CALL message %p\n", (void *)msg));
|
||||||
|
msg->msg.api_call->err = msg->msg.api_call->function(msg->msg.api_call);
|
||||||
|
sys_sem_signal(&msg->msg.api_call->sem);
|
||||||
|
break;
|
||||||
#endif /* LWIP_TCPIP_CORE_LOCKING */
|
#endif /* LWIP_TCPIP_CORE_LOCKING */
|
||||||
|
|
||||||
#if !LWIP_TCPIP_CORE_LOCKING_INPUT
|
#if !LWIP_TCPIP_CORE_LOCKING_INPUT
|
||||||
@ -331,6 +336,38 @@ tcpip_send_api_msg(tcpip_callback_fn fn, void *apimsg, sys_sem_t* sem)
|
|||||||
}
|
}
|
||||||
#endif /* !LWIP_TCPIP_CORE_LOCKING */
|
#endif /* !LWIP_TCPIP_CORE_LOCKING */
|
||||||
|
|
||||||
|
err_t tcpip_api_call(tcpip_api_call_fn fn, struct tcpip_api_call *call)
|
||||||
|
{
|
||||||
|
#if LWIP_TCPIP_CORE_LOCKING
|
||||||
|
LOCK_TCPIP_CORE();
|
||||||
|
call->err = fn(call);
|
||||||
|
UNLOCK_TCPIP_CORE();
|
||||||
|
return call->err;
|
||||||
|
#else
|
||||||
|
|
||||||
|
if (sys_mbox_valid_val(mbox)) {
|
||||||
|
TCPIP_MSG_VAR_DECLARE(msg);
|
||||||
|
err_t err;
|
||||||
|
|
||||||
|
err = sys_sem_new(&call->sem, 0);
|
||||||
|
if (err != ERR_OK) {
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
TCPIP_MSG_VAR_ALLOC(msg);
|
||||||
|
TCPIP_MSG_VAR_REF(msg).type = TCPIP_MSG_API_CALL;
|
||||||
|
TCPIP_MSG_VAR_REF(msg).msg.api_call = call;
|
||||||
|
TCPIP_MSG_VAR_REF(msg).msg.api_call->function = fn;
|
||||||
|
sys_mbox_post(&mbox, &TCPIP_MSG_VAR_REF(msg));
|
||||||
|
sys_arch_sem_wait(&call->sem, 0);
|
||||||
|
sys_sem_free(&call->sem);
|
||||||
|
TCPIP_MSG_VAR_FREE(msg);
|
||||||
|
return ERR_OK;
|
||||||
|
}
|
||||||
|
return ERR_VAL;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allocate a structure for a static callback message and initialize it.
|
* Allocate a structure for a static callback message and initialize it.
|
||||||
* This is intended to be used to send "static" messages from interrupt context.
|
* This is intended to be used to send "static" messages from interrupt context.
|
||||||
|
@ -99,8 +99,21 @@ extern sys_mutex_t lock_tcpip_core;
|
|||||||
err_t tcpip_send_api_msg(tcpip_callback_fn fn, void *apimsg, sys_sem_t* sem);
|
err_t tcpip_send_api_msg(tcpip_callback_fn fn, void *apimsg, sys_sem_t* sem);
|
||||||
#endif /* !LWIP_TCPIP_CORE_LOCKING */
|
#endif /* !LWIP_TCPIP_CORE_LOCKING */
|
||||||
|
|
||||||
|
struct tcpip_api_call;
|
||||||
|
typedef err_t (*tcpip_api_call_fn)(struct tcpip_api_call* call);
|
||||||
|
struct tcpip_api_call
|
||||||
|
{
|
||||||
|
tcpip_api_call_fn function;
|
||||||
|
#if !LWIP_TCPIP_CORE_LOCKING
|
||||||
|
sys_sem_t sem;
|
||||||
|
#endif /* !LWIP_TCPIP_CORE_LOCKING */
|
||||||
|
err_t err;
|
||||||
|
};
|
||||||
|
err_t tcpip_api_call(tcpip_api_call_fn fn, struct tcpip_api_call *call);
|
||||||
|
|
||||||
enum tcpip_msg_type {
|
enum tcpip_msg_type {
|
||||||
TCPIP_MSG_API,
|
TCPIP_MSG_API,
|
||||||
|
TCPIP_MSG_API_CALL,
|
||||||
TCPIP_MSG_INPKT,
|
TCPIP_MSG_INPKT,
|
||||||
#if LWIP_TCPIP_TIMEOUT
|
#if LWIP_TCPIP_TIMEOUT
|
||||||
TCPIP_MSG_TIMEOUT,
|
TCPIP_MSG_TIMEOUT,
|
||||||
@ -117,6 +130,7 @@ struct tcpip_msg {
|
|||||||
tcpip_callback_fn function;
|
tcpip_callback_fn function;
|
||||||
void* msg;
|
void* msg;
|
||||||
} api;
|
} api;
|
||||||
|
struct tcpip_api_call *api_call;
|
||||||
struct {
|
struct {
|
||||||
struct pbuf *p;
|
struct pbuf *p;
|
||||||
struct netif *netif;
|
struct netif *netif;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user