You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by gn...@apache.org on 2020/01/31 19:30:47 UTC

[incubator-nuttx] 03/10: Move the lock from psock_release to sockfd_release

This is an automated email from the ASF dual-hosted git repository.

gnutt pushed a commit to branch pr192
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git

commit 449778e448e86c186eb2b0db1946dcf37dcba198
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Fri Jan 31 17:43:41 2020 +0800

    Move the lock from psock_release to sockfd_release
    
    since the kernel psock doesn't bind to any socketlist
    
    Change-Id: I30dcaaa96db64830660faeb2d37ce8545a514ec7
    Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
 net/socket/net_sockets.c | 45 +++++++++++++++++++++------------------------
 1 file changed, 21 insertions(+), 24 deletions(-)

diff --git a/net/socket/net_sockets.c b/net/socket/net_sockets.c
index d6523ed..233d48e 100644
--- a/net/socket/net_sockets.c
+++ b/net/socket/net_sockets.c
@@ -40,7 +40,6 @@
 #include <nuttx/config.h>
 
 #include <string.h>
-#include <semaphore.h>
 #include <assert.h>
 #include <sched.h>
 #include <errno.h>
@@ -48,6 +47,7 @@
 
 #include <nuttx/net/net.h>
 #include <nuttx/kmalloc.h>
+#include <nuttx/semaphore.h>
 
 #include "socket/socket.h"
 
@@ -192,30 +192,19 @@ void psock_release(FAR struct socket *psock)
 {
   if (psock != NULL)
     {
-      /* Take the list semaphore so that there will be no accesses
-       * to this socket structure.
+      /* Decrement the count if there the socket will persist
+       * after this.
        */
 
-      FAR struct socketlist *list = sched_getsockets();
-      if (list)
+      if (psock->s_crefs > 1)
         {
-          /* Decrement the count if there the socket will persist
-           * after this.
-           */
-
-          _net_semtake(list);
-          if (psock->s_crefs > 1)
-            {
-              psock->s_crefs--;
-            }
-          else
-            {
-              /* The socket will not persist... reset it */
-
-              memset(psock, 0, sizeof(struct socket));
-            }
+          psock->s_crefs--;
+        }
+      else
+        {
+          /* The socket will not persist... reset it */
 
-          _net_semgive(list);
+          memset(psock, 0, sizeof(struct socket));
         }
     }
 }
@@ -240,11 +229,19 @@ void sockfd_release(int sockfd)
 
   FAR struct socket *psock = sockfd_socket(sockfd);
 
-  /* Get the socket structure for this sockfd */
-
   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);
+        }
     }
 }