]> granicus.if.org Git - esp-idf/commitdiff
Add hack of explicitly locking stdout
authorAngus Gratton <angus@espressif.com>
Tue, 23 Aug 2016 09:10:52 +0000 (17:10 +0800)
committerWu Jian Gang <wujiangang@espressif.com>
Wed, 24 Aug 2016 05:49:17 +0000 (13:49 +0800)
This shouldn't be necessary as stdout is already locked by libc (see
comment.) Not sure which part isn't working.

components/esp32/syscalls.c

index a087c2caaa34d4622b2d0a461f79bda5fbe56e4a..8978154240cc971bbc052581ac1b23391891b0ee 100644 (file)
@@ -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;
 }