feat(newlib): Adds flockfile/funlockfile for safe multi-line printing

for printf, vprintf, etc.

Closes https://github.com/espressif/esp-idf/issues/2565
This commit is contained in:
Konstantin Kondrashov
2024-05-24 14:16:16 +03:00
parent 60532e7a80
commit b0457ee0ac
4 changed files with 94 additions and 0 deletions
+32
View File
@@ -0,0 +1,32 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <stdio.h>
#include <sys/lock.h>
#include <sys/reent.h>
void flockfile(FILE *fp)
{
if (fp && !(fp->_flags & __SSTR)) {
__lock_acquire_recursive(fp->_lock);
}
}
int ftrylockfile(FILE *fp)
{
if (fp && !(fp->_flags & __SSTR)) {
return __lock_try_acquire_recursive(fp->_lock);
}
return 0;
}
void funlockfile(FILE *fp)
{
if (fp && !(fp->_flags & __SSTR)) {
__lock_release_recursive(fp->_lock);
}
}