You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2022/07/21 09:03:34 UTC

[GitHub] [incubator-nuttx] pkarashchenko commented on a diff in pull request #5996: stdlib: generate uniformly distributed pseudo-random numbers

pkarashchenko commented on code in PR #5996:
URL: https://github.com/apache/incubator-nuttx/pull/5996#discussion_r926434616


##########
drivers/syslog/syslog_rpmsg_server.c:
##########
@@ -64,11 +70,77 @@ static void syslog_rpmsg_ns_unbind(FAR struct rpmsg_endpoint *ept);
 static int  syslog_rpmsg_ept_cb(FAR struct rpmsg_endpoint *ept,
                                 FAR void *data, size_t len, uint32_t src,
                                 FAR void *priv_);
+#ifdef CONFIG_SYSLOG_RPMSG_SERVER_CHARDEV
+static int syslog_rpmsg_file_ioctl(FAR struct file *filep, int cmd,
+                                   unsigned long arg);
+#endif
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+#ifdef CONFIG_SYSLOG_RPMSG_SERVER_CHARDEV
+static struct list_node g_list = LIST_INITIAL_VALUE(g_list);
+static mutex_t g_lock = NXMUTEX_INITIALIZER;
+
+static const struct file_operations g_syslog_rpmsg_fops =
+{
+  NULL,                    /* open */
+  NULL,                    /* close */
+  NULL,                    /* read */
+  NULL,                    /* write */
+  NULL,                    /* seek */
+  syslog_rpmsg_file_ioctl, /* ioctl */
+  NULL                     /* poll */
+#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS
+  , NULL                   /* unlink */
+#endif
+};
 
 /****************************************************************************
  * Private Functions
  ****************************************************************************/
 
+static int syslog_rpmsg_file_ioctl(FAR struct file *filep, int cmd,
+                                   unsigned long arg)
+{
+  FAR struct syslog_rpmsg_server_s *priv;
+  struct syslog_rpmsg_sync_s msg;
+  sem_t sem;
+  int ret = 0;
+
+  if (cmd != FIOC_DUMP)
+    {
+      return -ENOTTY;
+    }
+
+  nxsem_init(&sem, 0, 0);
+  nxsem_set_protocol(&sem, SEM_PRIO_NONE);
+
+  nxmutex_lock(&g_lock);
+  list_for_every_entry(&g_list, priv, struct syslog_rpmsg_server_s, node)
+    {
+      msg.cookie = (uint64_t)(uintptr_t)&sem;
+      msg.header.command = SYSLOG_RPMSG_SYNC;
+      ret = rpmsg_send(&priv->ept, &msg, sizeof(msg));
+      if (ret < 0)
+        {
+          continue;
+        }
+
+      ret = rpmsg_wait(&priv->ept, &sem);
+      if (ret < 0)
+        {
+          continue;
+        }
+    }
+
+  nxmutex_unlock(&g_lock);
+  nxsem_destroy(&sem);
+  return ret;

Review Comment:
   ```suggestion
     return OK;
   ```



##########
drivers/syslog/syslog_rpmsg_server.c:
##########
@@ -64,11 +70,77 @@ static void syslog_rpmsg_ns_unbind(FAR struct rpmsg_endpoint *ept);
 static int  syslog_rpmsg_ept_cb(FAR struct rpmsg_endpoint *ept,
                                 FAR void *data, size_t len, uint32_t src,
                                 FAR void *priv_);
+#ifdef CONFIG_SYSLOG_RPMSG_SERVER_CHARDEV
+static int syslog_rpmsg_file_ioctl(FAR struct file *filep, int cmd,
+                                   unsigned long arg);
+#endif
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+#ifdef CONFIG_SYSLOG_RPMSG_SERVER_CHARDEV
+static struct list_node g_list = LIST_INITIAL_VALUE(g_list);
+static mutex_t g_lock = NXMUTEX_INITIALIZER;
+
+static const struct file_operations g_syslog_rpmsg_fops =
+{
+  NULL,                    /* open */
+  NULL,                    /* close */
+  NULL,                    /* read */
+  NULL,                    /* write */
+  NULL,                    /* seek */
+  syslog_rpmsg_file_ioctl, /* ioctl */
+  NULL                     /* poll */
+#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS
+  , NULL                   /* unlink */
+#endif
+};
 
 /****************************************************************************
  * Private Functions
  ****************************************************************************/
 
+static int syslog_rpmsg_file_ioctl(FAR struct file *filep, int cmd,
+                                   unsigned long arg)
+{
+  FAR struct syslog_rpmsg_server_s *priv;
+  struct syslog_rpmsg_sync_s msg;
+  sem_t sem;
+  int ret = 0;

Review Comment:
   ```suggestion
     int ret;
   ```



##########
drivers/syslog/syslog_rpmsg.c:
##########
@@ -138,62 +154,62 @@ static void syslog_rpmsg_work(FAR void *priv_)
     {
       memcpy(msg->data, &priv->buffer[off], len_end);
       memcpy(msg->data + len_end, priv->buffer, len - len_end);
+      memset(&priv->buffer[off], 0, len_end);
+      memset(priv->buffer, 0, len - len_end);
     }
   else
     {
       memcpy(msg->data, &priv->buffer[off], len);
+      memset(&priv->buffer[off], 0, len);
     }
 
-  priv->trans_len = len;
-  priv->transfer  = true;
+  msg->count          = len;
+  priv->tail         += len;
+  msg->header.command = SYSLOG_RPMSG_TRANSFER;
+  rpmsg_send_nocopy(&priv->ept, msg, sizeof(*msg) + len);
+  len                 = SYSLOG_RPMSG_COUNT(priv);
 
   leave_critical_section(flags);
 
-  msg->header.command = SYSLOG_RPMSG_TRANSFER;
-  msg->count          = len;
-  rpmsg_send_nocopy(&priv->ept, msg, sizeof(*msg) + len);
+  if (len > 0)
+    {
+      goto again;

Review Comment:
   look more like a `do {} while` loop



##########
drivers/syslog/syslog_rpmsg_server.c:
##########
@@ -200,11 +283,16 @@ static int syslog_rpmsg_ept_cb(FAR struct rpmsg_endpoint *ept,
           memcpy(priv->tmpbuf + priv->nextpos, msg->data + printed, copied);
           priv->nextpos += copied;
         }
+    }
+#ifdef CONFIG_SYSLOG_RPMSG_SERVER_CHARDEV
+  else if (header->command == SYSLOG_RPMSG_SYNC)
+    {
+      FAR struct syslog_rpmsg_sync_s *msg = data;
+      sem_t *sem = (FAR sem_t *)(uintptr_t)msg->cookie;

Review Comment:
   ```suggestion
         FAR sem_t *sem = (FAR sem_t *)(uintptr_t)msg->cookie;
   ```



##########
drivers/syslog/syslog_rpmsg_server.c:
##########
@@ -64,11 +70,77 @@ static void syslog_rpmsg_ns_unbind(FAR struct rpmsg_endpoint *ept);
 static int  syslog_rpmsg_ept_cb(FAR struct rpmsg_endpoint *ept,
                                 FAR void *data, size_t len, uint32_t src,
                                 FAR void *priv_);
+#ifdef CONFIG_SYSLOG_RPMSG_SERVER_CHARDEV
+static int syslog_rpmsg_file_ioctl(FAR struct file *filep, int cmd,
+                                   unsigned long arg);
+#endif
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+#ifdef CONFIG_SYSLOG_RPMSG_SERVER_CHARDEV
+static struct list_node g_list = LIST_INITIAL_VALUE(g_list);
+static mutex_t g_lock = NXMUTEX_INITIALIZER;
+
+static const struct file_operations g_syslog_rpmsg_fops =
+{
+  NULL,                    /* open */
+  NULL,                    /* close */
+  NULL,                    /* read */
+  NULL,                    /* write */
+  NULL,                    /* seek */
+  syslog_rpmsg_file_ioctl, /* ioctl */
+  NULL                     /* poll */
+#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS
+  , NULL                   /* unlink */
+#endif
+};
 
 /****************************************************************************
  * Private Functions
  ****************************************************************************/
 
+static int syslog_rpmsg_file_ioctl(FAR struct file *filep, int cmd,
+                                   unsigned long arg)
+{
+  FAR struct syslog_rpmsg_server_s *priv;
+  struct syslog_rpmsg_sync_s msg;
+  sem_t sem;
+  int ret = 0;
+
+  if (cmd != FIOC_DUMP)
+    {
+      return -ENOTTY;
+    }
+
+  nxsem_init(&sem, 0, 0);
+  nxsem_set_protocol(&sem, SEM_PRIO_NONE);
+
+  nxmutex_lock(&g_lock);
+  list_for_every_entry(&g_list, priv, struct syslog_rpmsg_server_s, node)
+    {
+      msg.cookie = (uint64_t)(uintptr_t)&sem;
+      msg.header.command = SYSLOG_RPMSG_SYNC;
+      ret = rpmsg_send(&priv->ept, &msg, sizeof(msg));
+      if (ret < 0)
+        {
+          continue;
+        }
+
+      ret = rpmsg_wait(&priv->ept, &sem);
+      if (ret < 0)
+        {
+          continue;
+        }

Review Comment:
   ```suggestion
         ret = rpmsg_send(&priv->ept, &msg, sizeof(msg));
         if (ret >= 0)
           {
             rpmsg_wait(&priv->ept, &sem);
           }
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org