Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: wrap logging buffer writes in critical section in Windows logging implementation #1039

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
15 changes: 7 additions & 8 deletions FreeRTOS-Plus/Demo/Common/Logging/windows/Logging_WinSim.c
Original file line number Diff line number Diff line change
Expand Up @@ -402,16 +402,15 @@ void vLoggingPrintf( const char * pcFormat,
if( xLength2 >= ( xLength + sizeof( xLength ) ) )
{
/* First write in the length of the data, then write in the data
* itself. Raising the thread priority is used as a critical section
* as there are potentially multiple writers. The stream buffer is
* only thread safe when there is a single writer (likewise for
* reading from the buffer). */
xCurrentTask = GetCurrentThread();
iOriginalPriority = GetThreadPriority( xCurrentTask );
SetThreadPriority( GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A naive question: Why wasn't this able to achieve the same thing as taskENTER_CRITICAL()?

* itself. We are directly using taskENTER_CRITICAL() and
* taskEXIT_CRITICAL() to ensure the buffer writes are inside a
* critical section. */
taskENTER_CRITICAL();

uxStreamBufferAdd( xLogStreamBuffer, 0, ( const uint8_t * ) &( xLength ), sizeof( xLength ) );
uxStreamBufferAdd( xLogStreamBuffer, 0, ( const uint8_t * ) cOutputString, xLength );
SetThreadPriority( GetCurrentThread(), iOriginalPriority );

taskEXIT_CRITICAL();
}

/* xDirectPrint is initialized to pdTRUE, and while it remains true the
Expand Down
Loading