You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2022/01/05 04:39:09 UTC
[incubator-nuttx] branch master updated: net/usrsock: add support for CONFIG_NET_ALLOC_CONNS
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new 4603d10 net/usrsock: add support for CONFIG_NET_ALLOC_CONNS
4603d10 is described below
commit 4603d108be68d492db9be9c348860955930a8fe6
Author: chao.an <an...@xiaomi.com>
AuthorDate: Tue Jan 4 16:33:03 2022 +0800
net/usrsock: add support for CONFIG_NET_ALLOC_CONNS
Signed-off-by: chao.an <an...@xiaomi.com>
---
net/usrsock/usrsock_conn.c | 47 +++++++++++++++++++++++++++++-----------------
1 file changed, 30 insertions(+), 17 deletions(-)
diff --git a/net/usrsock/usrsock_conn.c b/net/usrsock/usrsock_conn.c
index 28e7c29..209914f 100644
--- a/net/usrsock/usrsock_conn.c
+++ b/net/usrsock/usrsock_conn.c
@@ -33,6 +33,7 @@
#include <arch/irq.h>
+#include <nuttx/kmalloc.h>
#include <nuttx/semaphore.h>
#include <nuttx/net/netconfig.h>
#include <nuttx/net/net.h>
@@ -45,7 +46,9 @@
/* The array containing all usrsock connections. */
+#ifndef CONFIG_NET_ALLOC_CONNS
static struct usrsock_conn_s g_usrsock_connections[CONFIG_NET_USRSOCK_CONNS];
+#endif
/* A list of all free usrsock connections */
@@ -94,23 +97,36 @@ static void _usrsock_semgive(FAR sem_t *sem)
FAR struct usrsock_conn_s *usrsock_alloc(void)
{
FAR struct usrsock_conn_s *conn;
+#ifdef CONFIG_NET_ALLOC_CONNS
+ int i;
+#endif
/* The free list is protected by a semaphore (that behaves like a mutex). */
_usrsock_semtake(&g_free_sem);
+#ifdef CONFIG_NET_ALLOC_CONNS
+ if (dq_peek(&g_free_usrsock_connections) == NULL)
+ {
+ conn = kmm_zalloc(sizeof(*conn) * CONFIG_NET_USRSOCK_CONNS);
+ if (conn != NULL)
+ {
+ for (i = 0; i < CONFIG_NET_USRSOCK_CONNS; i++)
+ {
+ dq_addlast(&conn[i].node, &g_free_usrsock_connections);
+ }
+ }
+ }
+#endif
+
conn = (FAR struct usrsock_conn_s *)
- dq_remfirst(&g_free_usrsock_connections);
+ dq_remfirst(&g_free_usrsock_connections);
if (conn)
{
/* Make sure that the connection is marked as uninitialized */
- memset(conn, 0, sizeof(*conn));
nxsem_init(&conn->resp.sem, 0, 1);
- conn->dev = NULL;
conn->usockid = -1;
conn->state = USRSOCK_CONN_STATE_UNINITIALIZED;
- conn->list = NULL;
- conn->connected = false;
/* Enqueue the connection into the active list */
@@ -146,10 +162,6 @@ void usrsock_free(FAR struct usrsock_conn_s *conn)
nxsem_destroy(&conn->resp.sem);
memset(conn, 0, sizeof(*conn));
- conn->dev = NULL;
- conn->usockid = -1;
- conn->state = USRSOCK_CONN_STATE_UNINITIALIZED;
- conn->list = NULL;
/* Free the connection */
@@ -218,10 +230,10 @@ int usrsock_setup_request_callback(FAR struct usrsock_conn_s *conn,
nxsem_init(&pstate->recvsem, 0, 0);
nxsem_set_protocol(&pstate->recvsem, SEM_PRIO_NONE);
- pstate->conn = conn;
- pstate->result = -EAGAIN;
+ pstate->conn = conn;
+ pstate->result = -EAGAIN;
pstate->completed = false;
- pstate->unlock = false;
+ pstate->unlock = false;
/* Set up the callback in the connection */
@@ -316,7 +328,10 @@ void usrsock_setup_datain(FAR struct usrsock_conn_s *conn,
void usrsock_initialize(void)
{
+#ifndef CONFIG_NET_ALLOC_CONNS
+ FAR struct usrsock_conn_s *conn;
int i;
+#endif
/* Initialize the queues */
@@ -324,20 +339,18 @@ void usrsock_initialize(void)
dq_init(&g_active_usrsock_connections);
nxsem_init(&g_free_sem, 0, 1);
+#ifndef CONFIG_NET_ALLOC_CONNS
for (i = 0; i < CONFIG_NET_USRSOCK_CONNS; i++)
{
- FAR struct usrsock_conn_s *conn = &g_usrsock_connections[i];
+ conn = &g_usrsock_connections[i];
/* Mark the connection closed and move it to the free list */
- memset(conn, 0, sizeof(*conn));
- conn->dev = NULL;
conn->usockid = -1;
conn->state = USRSOCK_CONN_STATE_UNINITIALIZED;
- conn->list = NULL;
- conn->flags = 0;
dq_addlast(&conn->node, &g_free_usrsock_connections);
}
+#endif
/* Register /dev/usrsock character device. */