From: Angus Gratton Date: Tue, 23 Aug 2016 09:10:52 +0000 (+0800) Subject: Add hack of explicitly locking stdout X-Git-Tag: v0.9~71^2~10 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=94104f0fe87f97dd3289110d087eee54154146aa;p=esp-idf Add hack of explicitly locking stdout This shouldn't be necessary as stdout is already locked by libc (see comment.) Not sure which part isn't working. --- diff --git a/components/esp32/syscalls.c b/components/esp32/syscalls.c index a087c2caaa..8978154240 100644 --- a/components/esp32/syscalls.c +++ b/components/esp32/syscalls.c @@ -138,6 +138,13 @@ int _open_r(struct _reent *r, const char * path, int flags, int mode) { ssize_t _write_r(struct _reent *r, int fd, const void * data, size_t size) { const char* p = (const char*) data; if (fd == STDOUT_FILENO) { + /* THIS IS A HACK!!! The stdout "file" should be locked while + this code is called (it's locked fflush.c:280 before + __sflush_r is called.) It shouldn't be necessary to + re-lock, but due to some unknown bug it is... + */ + static _lock_t stdout_lock; + _lock_acquire_recursive(&stdout_lock); while(size--) { #if CONFIG_NEWLIB_STDOUT_ADDCR if (*p=='\n') { @@ -147,6 +154,7 @@ ssize_t _write_r(struct _reent *r, int fd, const void * data, size_t size) { uart_tx_one_char(*p); ++p; } + _lock_release_recursive(&stdout_lock); } return size; }