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 2021/07/07 11:41:52 UTC

[GitHub] [incubator-nuttx] fjpanag commented on a change in pull request #4028: syslog: fix log confusion when multi task writing together

fjpanag commented on a change in pull request #4028:
URL: https://github.com/apache/incubator-nuttx/pull/4028#discussion_r665291248



##########
File path: drivers/syslog/ramlog.c
##########
@@ -283,12 +286,89 @@ static int ramlog_addchar(FAR struct ramlog_dev_s *priv, char ch)
   return OK;
 }
 
+/****************************************************************************
+ * Name: ramlog_addbuf
+ ****************************************************************************/
+
+static ssize_t ramlog_addbuf(FAR struct ramlog_dev_s *priv,
+                             FAR const char *buffer, size_t len)
+{
+  int readers_waken;
+  ssize_t nwritten;
+  char ch;
+  int ret;
+
+  ret = nxsem_wait(&priv->rl_exclsem);
+  if (ret < 0)
+    {
+      return ret;
+    }
+
+  for (nwritten = 0; (size_t)nwritten < len; nwritten++)
+    {
+      /* Get the next character to output */
+
+      ch = buffer[nwritten];
+
+      /* Then output the character */
+
+      ret = ramlog_addchar(priv, ch);
+      if (ret < 0)
+        {
+          /* The buffer is full and nothing was saved.  The remaining
+           * data to be written is dropped on the floor.
+           */
+
+          break;
+        }
+    }
+
+  /* Was anything written? */
+
+  if (nwritten > 0)
+    {
+      readers_waken = 0;
+
+#ifndef CONFIG_RAMLOG_NONBLOCKING
+      /* Are there threads waiting for read data? */
+
+      readers_waken = ramlog_readnotify(priv);
+#endif
+
+      /* If there are multiple readers, some of them might block despite
+       * POLLIN because first reader might read all data. Favor readers
+       * and notify poll waiters only if no reader was awaken, even if the
+       * latter may starve.
+       *
+       * This also implies we do not have to make these two notify
+       * operations a critical section.
+       */
+
+      if (readers_waken == 0)
+        {
+          /* Notify all poll/select waiters that they can read from the
+           * FIFO.
+           */
+
+          ramlog_pollnotify(priv, POLLIN);
+        }
+    }
+
+  /* We always have to return the number of bytes requested and NOT the
+   * number of bytes that were actually written.  Otherwise, callers
+   * probably retry, causing same error condition again.
+   */
+
+  nxsem_post(&priv->rl_exclsem);
+  return len;
+}
+
 /****************************************************************************
  * Name: ramlog_read

Review comment:
       Just a minor nit. The comment was not updated to reflect the new function's name.




-- 
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