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 2023/07/21 12:47:04 UTC

[nuttx] branch master updated: nuttx/sim: use workquene instead rptun_loop

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/nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new 0b01340aec nuttx/sim: use workquene instead rptun_loop
0b01340aec is described below

commit 0b01340aec1e96e668cae01b554513c1985a46b6
Author: yintao <yi...@xiaomi.com>
AuthorDate: Tue Jul 11 12:07:09 2023 +0800

    nuttx/sim: use workquene instead rptun_loop
    
    Signed-off-by: yintao <yi...@xiaomi.com>
---
 arch/sim/src/sim/sim_initialize.c |  4 --
 arch/sim/src/sim/sim_internal.h   |  1 -
 arch/sim/src/sim/sim_rptun.c      | 78 +++++++++++++++++++++------------------
 3 files changed, 42 insertions(+), 41 deletions(-)

diff --git a/arch/sim/src/sim/sim_initialize.c b/arch/sim/src/sim/sim_initialize.c
index a584d26da1..6f5718a7a6 100644
--- a/arch/sim/src/sim/sim_initialize.c
+++ b/arch/sim/src/sim/sim_initialize.c
@@ -187,10 +187,6 @@ static int sim_loop_task(int argc, char **argv)
       host_usrsock_loop();
 #endif
 
-#ifdef CONFIG_RPTUN
-      sim_rptun_loop();
-#endif
-
 #ifdef CONFIG_SIM_HCISOCKET
       sim_bthcisock_loop();
 #endif
diff --git a/arch/sim/src/sim/sim_internal.h b/arch/sim/src/sim/sim_internal.h
index b8cccd946b..67432a026a 100644
--- a/arch/sim/src/sim/sim_internal.h
+++ b/arch/sim/src/sim/sim_internal.h
@@ -350,7 +350,6 @@ void sim_netdriver_loop(void);
 
 #ifdef CONFIG_RPTUN
 int sim_rptun_init(const char *shmemname, const char *cpuname, bool master);
-void sim_rptun_loop(void);
 #endif
 
 /* sim_hcisocket.c **********************************************************/
diff --git a/arch/sim/src/sim/sim_rptun.c b/arch/sim/src/sim/sim_rptun.c
index 86d58d33da..ba06d8bd10 100644
--- a/arch/sim/src/sim/sim_rptun.c
+++ b/arch/sim/src/sim/sim_rptun.c
@@ -25,9 +25,16 @@
 #include <nuttx/drivers/addrenv.h>
 #include <nuttx/rptun/rptun.h>
 #include <nuttx/list.h>
+#include <nuttx/wqueue.h>
 
 #include "sim_internal.h"
 
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define SIM_RPTUN_WORK_DELAY 1
+
 /****************************************************************************
  * Private Types
  ****************************************************************************/
@@ -43,7 +50,6 @@ struct sim_rptun_shmem_s
 
 struct sim_rptun_dev_s
 {
-  struct list_node          node;
   struct rptun_dev_s        rptun;
   rptun_callback_t          callback;
   void                     *arg;
@@ -53,6 +59,10 @@ struct sim_rptun_dev_s
   struct simple_addrenv_s   addrenv[2];
   char                      cpuname[RPMSG_NAME_SIZE + 1];
   char                      shmemname[RPMSG_NAME_SIZE + 1];
+
+  /* Work queue for transmit */
+
+  struct work_s             worker;
 };
 
 /****************************************************************************
@@ -195,6 +205,35 @@ static int sim_rptun_register_callback(struct rptun_dev_s *dev,
   return 0;
 }
 
+static void sim_rptun_work(void *arg)
+{
+  struct sim_rptun_dev_s *dev = arg;
+
+  if (dev->shmem != NULL)
+    {
+      bool should_notify = false;
+
+      if (dev->master && dev->seq != dev->shmem->seqs)
+        {
+          dev->seq = dev->shmem->seqs;
+          should_notify = true;
+        }
+      else if (!dev->master && dev->seq != dev->shmem->seqm)
+        {
+          dev->seq = dev->shmem->seqm;
+          should_notify = true;
+        }
+
+      if (should_notify && dev->callback != NULL)
+        {
+          dev->callback(dev->arg, RPTUN_NOTIFY_ALL);
+        }
+    }
+
+  work_queue(HPWORK, &dev->worker,
+            sim_rptun_work, dev, SIM_RPTUN_WORK_DELAY);
+}
+
 /****************************************************************************
  * Private Data
  ****************************************************************************/
@@ -213,42 +252,10 @@ static const struct rptun_ops_s g_sim_rptun_ops =
   .register_callback = sim_rptun_register_callback,
 };
 
-static struct list_node g_dev_list = LIST_INITIAL_VALUE(g_dev_list);
-
 /****************************************************************************
  * Public Functions
  ****************************************************************************/
 
-void sim_rptun_loop(void)
-{
-  struct sim_rptun_dev_s *dev;
-
-  list_for_every_entry(&g_dev_list, dev,
-                       struct sim_rptun_dev_s, node)
-    {
-      if (dev->shmem != NULL)
-        {
-          bool should_notify = false;
-
-          if (dev->master && dev->seq != dev->shmem->seqs)
-            {
-              dev->seq = dev->shmem->seqs;
-              should_notify = true;
-            }
-          else if (!dev->master && dev->seq != dev->shmem->seqm)
-            {
-              dev->seq = dev->shmem->seqm;
-              should_notify = true;
-            }
-
-          if (should_notify && dev->callback != NULL)
-            {
-              dev->callback(dev->arg, RPTUN_NOTIFY_ALL);
-            }
-        }
-    }
-}
-
 int sim_rptun_init(const char *shmemname, const char *cpuname, bool master)
 {
   struct sim_rptun_dev_s *dev;
@@ -264,14 +271,13 @@ int sim_rptun_init(const char *shmemname, const char *cpuname, bool master)
   dev->rptun.ops = &g_sim_rptun_ops;
   strlcpy(dev->cpuname, cpuname, RPMSG_NAME_SIZE);
   strlcpy(dev->shmemname, shmemname, RPMSG_NAME_SIZE);
-  list_add_tail(&g_dev_list, &dev->node);
 
   ret = rptun_initialize(&dev->rptun);
   if (ret < 0)
     {
-      list_delete(&dev->node);
       kmm_free(dev);
+      return ret;
     }
 
-  return ret;
+  return work_queue(HPWORK, &dev->worker, sim_rptun_work, dev, 0);
 }