note: optimize noteram_add, copy as much content as possible at a time
Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
This commit is contained in:
parent
081b04f05e
commit
6e35a51feb
@ -567,7 +567,8 @@ static void noteram_add(FAR struct note_driver_s *drv,
|
||||
{
|
||||
FAR const char *buf = note;
|
||||
unsigned int head;
|
||||
unsigned int next;
|
||||
unsigned int remain;
|
||||
unsigned int space;
|
||||
irqstate_t flags;
|
||||
|
||||
flags = spin_lock_irqsave_wo_note(&g_noteram_lock);
|
||||
@ -578,46 +579,37 @@ static void noteram_add(FAR struct note_driver_s *drv,
|
||||
return;
|
||||
}
|
||||
|
||||
/* Get the index to the head of the circular buffer */
|
||||
|
||||
DEBUGASSERT(note != NULL && notelen < CONFIG_DRIVERS_NOTERAM_BUFSIZE);
|
||||
head = g_noteram_info.ni_head;
|
||||
remain = CONFIG_DRIVERS_NOTERAM_BUFSIZE - noteram_length();
|
||||
|
||||
/* Loop until all bytes have been transferred to the circular buffer */
|
||||
|
||||
while (notelen > 0)
|
||||
if (remain < notelen)
|
||||
{
|
||||
/* Get the next head index. Would it collide with the current tail
|
||||
* index?
|
||||
*/
|
||||
|
||||
next = noteram_next(head, 1);
|
||||
if (next == g_noteram_info.ni_tail)
|
||||
if (g_noteram_info.ni_overwrite == NOTERAM_MODE_OVERWRITE_DISABLE)
|
||||
{
|
||||
if (g_noteram_info.ni_overwrite == NOTERAM_MODE_OVERWRITE_DISABLE)
|
||||
{
|
||||
/* Stop recording if not in overwrite mode */
|
||||
/* Stop recording if not in overwrite mode */
|
||||
|
||||
g_noteram_info.ni_overwrite = NOTERAM_MODE_OVERWRITE_OVERFLOW;
|
||||
spin_unlock_irqrestore_wo_note(&g_noteram_lock, flags);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Yes, then remove the note at the tail index */
|
||||
|
||||
noteram_remove();
|
||||
g_noteram_info.ni_overwrite = NOTERAM_MODE_OVERWRITE_OVERFLOW;
|
||||
spin_unlock_irqrestore_wo_note(&g_noteram_lock, flags);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Save the next byte at the head index */
|
||||
/* Remove the note at the tail index , make sure there is enough space
|
||||
*/
|
||||
|
||||
g_noteram_info.ni_buffer[head] = *buf++;
|
||||
|
||||
head = next;
|
||||
notelen--;
|
||||
do
|
||||
{
|
||||
noteram_remove();
|
||||
remain = CONFIG_DRIVERS_NOTERAM_BUFSIZE - noteram_length();
|
||||
}
|
||||
while (remain < notelen);
|
||||
}
|
||||
|
||||
g_noteram_info.ni_head = head;
|
||||
|
||||
head = g_noteram_info.ni_head;
|
||||
space = CONFIG_DRIVERS_NOTERAM_BUFSIZE - head;
|
||||
space = space < notelen ? space : notelen;
|
||||
memcpy(g_noteram_info.ni_buffer + head, note, space);
|
||||
memcpy(g_noteram_info.ni_buffer, buf + space, notelen - space);
|
||||
g_noteram_info.ni_head = noteram_next(head, notelen);
|
||||
spin_unlock_irqrestore_wo_note(&g_noteram_lock, flags);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user