diff options
author | Matt Joyce <matthew.joyce@embedded-brains.de> | 2022-02-22 11:18:38 +0100 |
---|---|---|
committer | Corinna Vinschen <corinna@vinschen.de> | 2022-02-22 12:38:46 +0100 |
commit | 44b60f0c4ba597c55dcac4f2d3119a3055c80ba1 (patch) | |
tree | e5286802e8b24fcbb7437f00163daaab0f439f2c /winsup | |
parent | 054b00d96a81ca1169a1dd2d63d79b7ac03919ac (diff) | |
download | newlib-44b60f0c4ba597c55dcac4f2d3119a3055c80ba1.zip newlib-44b60f0c4ba597c55dcac4f2d3119a3055c80ba1.tar.gz newlib-44b60f0c4ba597c55dcac4f2d3119a3055c80ba1.tar.bz2 |
Make __sdidinit unused
Remove dependency on __sdidinit member of struct _reent to check
object initialization. Like __sdidinit, the __cleanup member of
struct _reent is initialized in the __sinit() function. Checking
initialization against __cleanup serves the same purpose and will
reduce overhead in the __sfp() function in a follow up patch.
Diffstat (limited to 'winsup')
-rw-r--r-- | winsup/cygwin/cygtls.cc | 10 | ||||
-rw-r--r-- | winsup/cygwin/cygtls.h | 1 | ||||
-rw-r--r-- | winsup/cygwin/dcrt0.cc | 10 | ||||
-rw-r--r-- | winsup/cygwin/thread.cc | 4 |
4 files changed, 15 insertions, 10 deletions
diff --git a/winsup/cygwin/cygtls.cc b/winsup/cygwin/cygtls.cc index 1a2213d..c8352ad 100644 --- a/winsup/cygwin/cygtls.cc +++ b/winsup/cygwin/cygtls.cc @@ -60,8 +60,8 @@ _cygtls::init_thread (void *x, DWORD (*func) (void *, void *)) local_clib._stdin = _GLOBAL_REENT->_stdin; local_clib._stdout = _GLOBAL_REENT->_stdout; local_clib._stderr = _GLOBAL_REENT->_stderr; - local_clib.__sdidinit = _GLOBAL_REENT->__sdidinit ? -1 : 0; - local_clib.__cleanup = _GLOBAL_REENT->__cleanup; + if (_GLOBAL_REENT->__cleanup) + local_clib.__cleanup = _cygtls::cleanup_early; local_clib.__sglue._niobs = 3; local_clib.__sglue._iobs = &_GLOBAL_REENT->__sf[0]; } @@ -149,6 +149,12 @@ _cygtls::remove (DWORD wait) } } +void +_cygtls::cleanup_early (struct _reent *) +{ + /* Do nothing */ +} + #ifdef __x86_64__ void san::leave () { diff --git a/winsup/cygwin/cygtls.h b/winsup/cygwin/cygtls.h index a2e3676..c2c4141 100644 --- a/winsup/cygwin/cygtls.h +++ b/winsup/cygwin/cygtls.h @@ -272,6 +272,7 @@ public: will_wait_for_signal = false; } void handle_SIGCONT (); + static void cleanup_early(struct _reent *); private: void __reg3 call2 (DWORD (*) (void *, void *), void *, void *); void remove_pending_sigs (); diff --git a/winsup/cygwin/dcrt0.cc b/winsup/cygwin/dcrt0.cc index f3d09c1..e757c47 100644 --- a/winsup/cygwin/dcrt0.cc +++ b/winsup/cygwin/dcrt0.cc @@ -824,15 +824,13 @@ main_thread_sinit () As soon as the main thread calls a stdio function, this would be rectified. But if another thread calls a stdio function on stdin/out/err before the main thread does, all the required - initialization of stdin/out/err will be done, but _REENT->__sdidinit - is *still* 0. This in turn will result in a call to __sinit in the + initialization of stdin/out/err will be done, but _REENT->__cleanup + is *still* NULL. This in turn will result in a call to __sinit in the wrong spot. The input or output buffer will be NULLed and nothing is read or written in the first stdio function call in the main thread. - To fix this issue we have to copy over the relevant part of _GLOBAL_REENT - to _REENT here again. */ - _REENT->__sdidinit = -1; - _REENT->__cleanup = _GLOBAL_REENT->__cleanup; + To fix this issue we set __cleanup to _cygtls::cleanup_early here. */ + _REENT->__cleanup = _cygtls::cleanup_early; } /* Take over from libc's crt0.o and start the application. Note the diff --git a/winsup/cygwin/thread.cc b/winsup/cygwin/thread.cc index fcfd75c..b7da4d0 100644 --- a/winsup/cygwin/thread.cc +++ b/winsup/cygwin/thread.cc @@ -564,8 +564,8 @@ pthread::exit (void *value_ptr) mutex.unlock (); } - if (_my_tls.local_clib.__sdidinit < 0) - _my_tls.local_clib.__sdidinit = 0; + if (_my_tls.local_clib.__cleanup == _cygtls::cleanup_early) + _my_tls.local_clib.__cleanup = NULL; _reclaim_reent (_REENT); if (InterlockedDecrement (&MT_INTERFACE->threadcount) == 0) |