From 73e5838b97a6cf0888660d5ca7609a06e65e3498 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Tue, 25 May 2004 06:54:37 +0000 Subject: [PATCH] fix InitializePidThreadHelpers sometimes doing emory allocation in crash conditions fix InitializePidThreadHelpers initializing multiple times --- .../src/archutils/Unix/LinuxThreadHelpers.cpp | 41 +++++++++++-------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/stepmania/src/archutils/Unix/LinuxThreadHelpers.cpp b/stepmania/src/archutils/Unix/LinuxThreadHelpers.cpp index 6c82c0578f..32c470dc0a 100644 --- a/stepmania/src/archutils/Unix/LinuxThreadHelpers.cpp +++ b/stepmania/src/archutils/Unix/LinuxThreadHelpers.cpp @@ -30,14 +30,35 @@ static bool g_bUsingNPTL = false; static _syscall0(pid_t,gettid) -static bool UsingNPTL() +#ifndef _CS_GNU_LIBPTHREAD_VERSION +#define _CS_GNU_LIBPTHREAD_VERSION 3 +#endif + + +CString ThreadsVersion() { - return ThreadsVersion().Left(4) == "NPTL"; + char buf[1024] = "(error)"; + int ret = confstr( _CS_GNU_LIBPTHREAD_VERSION, buf, sizeof(buf) ); + if( ret == -1 ) + return "(unknown)"; + + return buf; } +/* Crash-conditions-safe: */ +static bool UsingNPTL() +{ + char buf[1024] = ""; + int ret = confstr( _CS_GNU_LIBPTHREAD_VERSION, buf, sizeof(buf) ); + if( ret == -1 ) + return false; + + return !strncmp( buf, "NPTL", 4 ); +} +/* Crash-conditions-safe: */ void InitializePidThreadHelpers() { - bool bInitialized = false; + static bool bInitialized = false; if( bInitialized ) return; bInitialized = true; @@ -95,20 +116,6 @@ static int PtraceDetach( int ThreadID ) } -#ifndef _CS_GNU_LIBPTHREAD_VERSION -#define _CS_GNU_LIBPTHREAD_VERSION 3 -#endif - -CString ThreadsVersion() -{ - char buf[1024] = "(error)"; - int ret = confstr( _CS_GNU_LIBPTHREAD_VERSION, buf, sizeof(buf) ); - if( ret == -1 ) - return "(unknown)"; - - return buf; -} - /* Get this thread's ID (this may be a TID or a PID). */ int GetCurrentThreadId() {