Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Joyce <matthew.joyce@embedded-brains.de>2022-05-16 12:51:54 +0300
committerSebastian Huber <sebastian.huber@embedded-brains.de>2022-07-13 07:55:46 +0300
commitea99f21ce6c8a332845439ea87f792dbaf679d42 (patch)
tree94cfcaf461882955f7461b09d6c4c0e2f321e66e /newlib/libc/stdio
parent1a0908203606527b6ac0ed438669b5bcd247a5f9 (diff)
Add --enable-newlib-reent-thread-local option
By default, Newlib uses a huge object of type struct _reent to store thread-specific data. This object is returned by __getreent() if the __DYNAMIC_REENT__ Newlib configuration option is defined. The reentrancy structure contains for example errno and the standard input, output, and error file streams. This means that if an application only uses errno it has a dependency on the file stream support even if it does not use it. This is an issue for lower end targets and applications which need to qualify the software according to safety standards (for example ECSS-E-ST-40C, ECSS-Q-ST-80C, IEC 61508, ISO 26262, DO-178, DO-330, DO-333). If the new _REENT_THREAD_LOCAL configuration option is enabled, then struct _reent is replaced by dedicated thread-local objects for each struct _reent member. The thread-local objects are defined in translation units which use the corresponding object.
Diffstat (limited to 'newlib/libc/stdio')
-rw-r--r--newlib/libc/stdio/findfp.c7
-rw-r--r--newlib/libc/stdio/tmpnam.c5
2 files changed, 12 insertions, 0 deletions
diff --git a/newlib/libc/stdio/findfp.c b/newlib/libc/stdio/findfp.c
index fbdb7f2f2..c43028209 100644
--- a/newlib/libc/stdio/findfp.c
+++ b/newlib/libc/stdio/findfp.c
@@ -32,6 +32,13 @@ __FILE __sf[3];
struct _glue __sglue = {NULL, 3, &__sf[0]};
+#ifdef _REENT_THREAD_LOCAL
+_Thread_local __FILE *_tls_stdin = &__sf[0];
+_Thread_local __FILE *_tls_stdout = &__sf[1];
+_Thread_local __FILE *_tls_stderr = &__sf[2];
+_Thread_local void (*_tls_cleanup)(struct _reent *);
+#endif
+
#ifdef _STDIO_BSD_SEMANTICS
/* BSD and Glibc systems only flush streams which have been written to
at exit time. Calling flush rather than close for speed, as on
diff --git a/newlib/libc/stdio/tmpnam.c b/newlib/libc/stdio/tmpnam.c
index 2767b4b20..51dfd1cea 100644
--- a/newlib/libc/stdio/tmpnam.c
+++ b/newlib/libc/stdio/tmpnam.c
@@ -82,6 +82,11 @@ The global pointer <<environ>> is also required.
#include <reent.h>
#include <errno.h>
+#ifdef _REENT_THREAD_LOCAL
+_Thread_local int _tls_inc;
+_Thread_local char _tls_emergency;
+#endif
+
/* Try to open the file specified, if it can't be opened then try
another one. Return nonzero if successful, otherwise zero. */