netlink: Shouldn't call netlink_notify_response in netlink_poll

to avoid sleep inside netlink_poll

Change-Id: Id801c2dae805455a9b91f2e091d001679f0b3d4b
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
Xiang Xiao 2020-04-08 01:50:01 +08:00 committed by patacongo
parent 9fb6eee5fe
commit 3421ec90b4
3 changed files with 1 additions and 118 deletions

View file

@ -261,23 +261,6 @@ netlink_get_response(FAR struct socket *psock);
bool netlink_check_response(FAR struct socket *psock);
/****************************************************************************
* Name: netlink_notify_response
*
* Description:
* Notify a thread when a response is available. The thread will be
* notified via work queue notifier when the response becomes available.
*
* Returned Value:
* Zero (OK) is returned if the response is already available. No
* notification will be sent.
* One is returned if the notification was successfully setup.
* A negated errno value is returned on any failure.
*
****************************************************************************/
int netlink_notify_response(FAR struct socket *psock);
/****************************************************************************
* Name: netlink_route_sendto()
*

View file

@ -432,66 +432,4 @@ bool netlink_check_response(FAR struct socket *psock)
return (sq_peek(&conn->resplist) != NULL);
}
/****************************************************************************
* Name: netlink_notify_response
*
* Description:
* Notify a thread when a response is available. The thread will be
* notified via work queue notifier when the response becomes available.
*
* Returned Value:
* Zero (OK) is returned if the response is already available. No
* notification will be sent.
* One is returned if the notification was successfully setup.
* A negated errno value is returned on any failure.
*
****************************************************************************/
int netlink_notify_response(FAR struct socket *psock)
{
FAR struct netlink_conn_s *conn;
int ret = 0;
DEBUGASSERT(psock != NULL && psock->s_conn != NULL);
conn = (FAR struct netlink_conn_s *)psock->s_conn;
/* Check if the response is available */
net_lock();
if (((FAR struct netlink_response_s *)sq_peek(&conn->resplist)) == NULL)
{
sem_t waitsem;
/* No.. Set up a semaphore to notify us when a response is queued. */
(void)sem_init(&waitsem, 0, 0);
(void)nxsem_setprotocol(&waitsem, SEM_PRIO_NONE);
/* Set up a notifier to post the semaphore when a response is
* received.
*/
ret = netlink_notifier_setup(netlink_response_available, conn,
&waitsem);
if (ret < 0)
{
nerr("ERROR: netlink_notifier_setup() failed: %d\n", ret);
}
else
{
/* Wait for a response to be queued */
_netlink_semtake(&waitsem);
}
/* Tear-down the notifier and the semaphore */
netlink_notifier_teardown(conn);
sem_destroy(&waitsem);
}
net_unlock();
return ret < 0 ? ret : OK;
}
#endif /* CONFIG_NET_NETLINK */

View file

@ -561,7 +561,7 @@ static int netlink_poll(FAR struct socket *psock, FAR struct pollfd *fds,
bool setup)
{
FAR struct netlink_conn_s *conn;
int ret;
int ret = OK;
DEBUGASSERT(psock != NULL && psock->s_conn != NULL);
conn = (FAR struct netlink_conn_s *)psock->s_conn;
@ -626,44 +626,6 @@ static int netlink_poll(FAR struct socket *psock, FAR struct pollfd *fds,
conn->pollsem = NULL;
conn->pollevent = NULL;
}
else
{
/* Call netlink_notify_response() to receive a notification
* when a response has been queued.
*/
ret = netlink_notify_response(psock);
if (ret < 0)
{
nerr("ERROR: netlink_notify_response() failed: %d\n", ret);
netlink_notifier_teardown(conn);
conn->pollsem = NULL;
conn->pollevent = NULL;
}
else if (ret == 0)
{
/* The return value of zero means that a response is
* already available and that no notification is
* forthcoming.
*/
netlink_notifier_teardown(conn);
conn->pollsem = NULL;
conn->pollevent = NULL;
fds->revents = POLLIN;
nxsem_post(fds->sem);
}
else
{
ret = OK;
}
}
}
else
{
/* There will not be any wakeups coming? Probably an error? */
ret = OK;
}
net_unlock();