tcpip.c tcpip_send_api_msg: Handle core locking case internally

This commit is contained in:
Dirk Ziegelmeier 2016-03-16 20:14:52 +01:00
parent bc51dddcaf
commit ea174560b1
2 changed files with 15 additions and 9 deletions

View File

@ -312,10 +312,11 @@ tcpip_untimeout(sys_timeout_handler h, void *arg)
#endif /* LWIP_TCPIP_TIMEOUT */
#if !LWIP_TCPIP_CORE_LOCKING
/**
* Generic way to dispatch an API message in TCPIP thread and wait for its
* completion by blocking on a semaphore.
* Synchronously calls function in TCPIP thread and waits for its completion
* by blocking on a provided semaphore pointer.
* It is recommended to use LWIP_TCPIP_CORE_LOCKING since this is the way
* with least runtime overhead.
*
* @param fn function to be called from TCPIP thread
* @param apimsg argument to API function
@ -327,6 +328,13 @@ tcpip_send_api_msg(tcpip_callback_fn fn, void *apimsg, sys_sem_t* sem)
{
LWIP_ASSERT("semaphore not initialized", sys_sem_valid(sem));
#if LWIP_TCPIP_CORE_LOCKING
LOCK_TCPIP_CORE();
fn(apimsg);
UNLOCK_TCPIP_CORE();
sys_arch_sem_wait(sem, 0);
return ERR_OK;
#else /* LWIP_TCPIP_CORE_LOCKING */
if (sys_mbox_valid_val(mbox)) {
TCPIP_MSG_VAR_DECLARE(msg);
@ -340,13 +348,13 @@ tcpip_send_api_msg(tcpip_callback_fn fn, void *apimsg, sys_sem_t* sem)
return ERR_OK;
}
return ERR_VAL;
#endif /* LWIP_TCPIP_CORE_LOCKING */
}
#endif /* !LWIP_TCPIP_CORE_LOCKING */
/**
* Synchronously calls function in TCPIP thread and waits for its completion.
* It is recommended to use LWIP_TCPIP_CORE_LOCKING (preferred) or
* LWIP_NETCONN_SEM_PER_THREAD.
* LWIP_NETCONN_SEM_PER_THREAD.
* If not, a semaphore is created and destroyed on every call which is usually
* an expensive/slow operation.
* @param fn Function to call
@ -361,7 +369,7 @@ err_t tcpip_api_call(tcpip_api_call_fn fn, struct tcpip_api_call *call)
err = fn(call);
UNLOCK_TCPIP_CORE();
return err;
#else
#else /* LWIP_TCPIP_CORE_LOCKING */
if (sys_mbox_valid_val(mbox)) {
TCPIP_MSG_VAR_DECLARE(msg);
err_t err;
@ -390,7 +398,7 @@ err_t tcpip_api_call(tcpip_api_call_fn fn, struct tcpip_api_call *call)
return ERR_OK;
}
return ERR_VAL;
#endif
#endif /* LWIP_TCPIP_CORE_LOCKING */
}
/**

View File

@ -95,9 +95,7 @@ extern sys_mutex_t lock_tcpip_core;
#define API_EXPR_DEREF(expr) *(expr)
#endif /* LWIP_MPU_COMPATIBLE */
#if !LWIP_TCPIP_CORE_LOCKING
err_t tcpip_send_api_msg(tcpip_callback_fn fn, void *apimsg, sys_sem_t* sem);
#endif /* !LWIP_TCPIP_CORE_LOCKING */
struct tcpip_api_call;
typedef err_t (*tcpip_api_call_fn)(struct tcpip_api_call* call);