Move the lock from psock_release to sockfd_release

Since the kernel psock doesn't bind to any socketlist
This commit is contained in:
Xiang Xiao
2020-01-31 17:43:41 +08:00
committed by Gregory Nutt
parent 0b860726db
commit 709dc19350
+21 -24
View File
@@ -40,7 +40,6 @@
#include <nuttx/config.h> #include <nuttx/config.h>
#include <string.h> #include <string.h>
#include <semaphore.h>
#include <assert.h> #include <assert.h>
#include <sched.h> #include <sched.h>
#include <errno.h> #include <errno.h>
@@ -48,6 +47,7 @@
#include <nuttx/net/net.h> #include <nuttx/net/net.h>
#include <nuttx/kmalloc.h> #include <nuttx/kmalloc.h>
#include <nuttx/semaphore.h>
#include "socket/socket.h" #include "socket/socket.h"
@@ -192,30 +192,19 @@ void psock_release(FAR struct socket *psock)
{ {
if (psock != NULL) if (psock != NULL)
{ {
/* Take the list semaphore so that there will be no accesses /* Decrement the count if there the socket will persist
* to this socket structure. * after this.
*/ */
FAR struct socketlist *list = sched_getsockets(); if (psock->s_crefs > 1)
if (list)
{ {
/* Decrement the count if there the socket will persist psock->s_crefs--;
* after this. }
*/ else
{
/* The socket will not persist... reset it */
_net_semtake(list); memset(psock, 0, sizeof(struct socket));
if (psock->s_crefs > 1)
{
psock->s_crefs--;
}
else
{
/* The socket will not persist... reset it */
memset(psock, 0, sizeof(struct socket));
}
_net_semgive(list);
} }
} }
} }
@@ -240,11 +229,19 @@ void sockfd_release(int sockfd)
FAR struct socket *psock = sockfd_socket(sockfd); FAR struct socket *psock = sockfd_socket(sockfd);
/* Get the socket structure for this sockfd */
if (psock) if (psock)
{ {
psock_release(psock); /* Take the list semaphore so that there will be no accesses
* to this socket structure.
*/
FAR struct socketlist *list = sched_getsockets();
if (list)
{
_net_semtake(list);
psock_release(psock);
_net_semgive(list);
}
} }
} }