aboutsummaryrefslogtreecommitdiff
path: root/winsup/cygwin/smallprint.cc
diff options
context:
space:
mode:
authorCorinna Vinschen <corinna@vinschen.de>2022-08-22 12:01:15 +0200
committerCorinna Vinschen <corinna@vinschen.de>2022-08-22 12:01:15 +0200
commit07ec40170a32cc614818ec8fa13cacef0a8252a0 (patch)
tree1b26e74ed9338d738f24bf9140f960ddb9ec92ff /winsup/cygwin/smallprint.cc
parent1b3a0effd40a0d75887ee9d2909dd4e8c5f20d37 (diff)
downloadnewlib-07ec40170a32cc614818ec8fa13cacef0a8252a0.zip
newlib-07ec40170a32cc614818ec8fa13cacef0a8252a0.tar.gz
newlib-07ec40170a32cc614818ec8fa13cacef0a8252a0.tar.bz2
Cygwin: smallprint.cc: Convert tmpbuf to lockless
The old technique was from a time when we had to reduce stack pressure by moving 64K buffers elsewhere. It was implemented using a static global buffer, guarded by a muto. However, that adds a lock which may unnecessarily serialize threads. Use Windows heap buffers per invocation instead. HeapAlloc/HeapFree are pretty fast, scale nicely in multithreaded scenarios and don't serialize threads unnecessarily. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Diffstat (limited to 'winsup/cygwin/smallprint.cc')
-rw-r--r--winsup/cygwin/smallprint.cc24
1 files changed, 9 insertions, 15 deletions
diff --git a/winsup/cygwin/smallprint.cc b/winsup/cygwin/smallprint.cc
index d64e3fd..0e8c6d9 100644
--- a/winsup/cygwin/smallprint.cc
+++ b/winsup/cygwin/smallprint.cc
@@ -56,32 +56,26 @@ static const char hex_str_lower[] = "0123456789abcdef";
class tmpbuf
{
- static WCHAR buf[NT_MAX_PATH];
- static muto lock;
- bool locked;
+ PWCHAR buf;
+
public:
operator WCHAR * ()
{
- if (!locked)
- {
- lock.init ("smallprint_buf")->acquire ();
- locked = true;
- }
+ if (!buf)
+ buf = (PWCHAR) HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY,
+ NT_MAX_PATH * sizeof (WCHAR));
return buf;
}
- operator char * () {return (char *) ((WCHAR *) *this);}
+ operator char * () { return (char *) ((WCHAR *) *this); }
- tmpbuf (): locked (false) {};
+ tmpbuf () : buf (NULL) {}
~tmpbuf ()
{
- if (locked)
- lock.release ();
+ if (buf)
+ HeapFree (GetProcessHeap (), 0, buf);
}
};
-WCHAR tmpbuf::buf[NT_MAX_PATH];
-NO_COPY muto tmpbuf::lock;
-
static char *
__rn (char *dst, int base, int dosign, long long val, int len, int pad, unsigned long long mask)
{