You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by "Gary-Hobson (via GitHub)" <gi...@apache.org> on 2023/03/13 05:39:51 UTC
[GitHub] [nuttx] Gary-Hobson commented on a diff in pull request #8755: ramlog: optimize ramlog_addchar, copy as much content as possible at a time
Gary-Hobson commented on code in PR #8755:
URL: https://github.com/apache/nuttx/pull/8755#discussion_r1133461392
##########
drivers/syslog/ramlog.c:
##########
@@ -286,84 +296,42 @@ static int ramlog_addchar(FAR struct ramlog_dev_s *priv, char ch)
flags = enter_critical_section();
- /* Calculate the write index AFTER the next byte is written */
-
- nexthead = priv->rl_head + 1;
- if (nexthead >= priv->rl_bufsize)
- {
- nexthead = 0;
- }
+ /* Calculate the size in the buffer */
- /* Would the next write overflow the circular buffer? */
+ space = (int)priv->rl_head - (int)priv->rl_tail >= 0 ?
+ priv->rl_bufsize - (priv->rl_head - priv->rl_tail) - 1:
+ priv->rl_tail - priv->rl_head - 1;
- if (nexthead == priv->rl_tail)
+ if (len > space)
{
#ifdef CONFIG_RAMLOG_OVERWRITE
- /* Yes... Overwrite with the latest log in the circular buffer */
-
- priv->rl_buffer[priv->rl_tail] = '\0';
- priv->rl_tail += 1;
- if (priv->rl_tail >= priv->rl_bufsize)
- {
- priv->rl_tail = 0;
- }
+ priv->rl_tail = (priv->rl_tail + len - space) % priv->rl_bufsize;
#else
- /* Yes... Return an indication that nothing was saved in the buffer. */
-
- leave_critical_section(flags);
- return -EBUSY;
+ len = space;
#endif
}
- /* No... copy the byte and re-enable interrupts */
-
- priv->rl_buffer[priv->rl_head] = ch;
- priv->rl_head = nexthead;
-
- leave_critical_section(flags);
- 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 = nxmutex_lock(&priv->rl_lock);
- if (ret < 0)
+ head = priv->rl_head;
+ if (priv->rl_head + len > priv->rl_bufsize)
Review Comment:
done
--
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