mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-23 00:41:02 +00:00
integrate patch from johannes@brilliantservice.co.jp
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@38212 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
69d9b09b67
commit
f9d7d1a577
5 changed files with 19022 additions and 3230 deletions
|
@ -1,3 +1,11 @@
|
|||
2014-11-28 johannes@brilliantservice.co.jp
|
||||
|
||||
* Source/NSThread.m: Set thread name visible to OS
|
||||
* configure.ac: test for pthread_set_name_np()
|
||||
Integrated Johannes patch with some changes to make things work if
|
||||
we set the name before starting the thread. Commend out ms-windows
|
||||
code which doesn't work yet.
|
||||
|
||||
2014-11-20 Sergei Golovin <Golovin.SV@gmail.com>
|
||||
|
||||
* Source/GSSocketStream.m:
|
||||
|
|
|
@ -775,6 +775,9 @@
|
|||
/* Define as the link to exe of process in /proc filesystem. */
|
||||
#undef PROCFS_EXE_LINK
|
||||
|
||||
/* Description: Define set name function for pthread */
|
||||
#undef PTHREAD_SETNAME
|
||||
|
||||
/* Define to 1 if the `setpgrp' function takes no argument. */
|
||||
#undef SETPGRP_VOID
|
||||
|
||||
|
|
|
@ -92,6 +92,58 @@
|
|||
# define IS_MAIN_PTHREAD (1)
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
/*
|
||||
* NSThread setName: method for windows.
|
||||
* FIXME ... This is code for the microsoft compiler;
|
||||
* how do we make it work for gcc/clang?
|
||||
*/
|
||||
#if defined(__MINGW__) && defined(HAVE_WINDOWS_H)
|
||||
// Usage: SetThreadName (-1, "MainThread");
|
||||
#include <windows.h>
|
||||
const DWORD MS_VC_EXCEPTION=0x406D1388;
|
||||
|
||||
#pragma pack(push,8)
|
||||
typedef struct tagTHREADNAME_INFO
|
||||
{
|
||||
DWORD dwType; // Must be 0x1000.
|
||||
LPCSTR szName; // Pointer to name (in user addr space).
|
||||
DWORD dwThreadID; // Thread ID (-1=caller thread).
|
||||
DWORD dwFlags; // Reserved for future use, must be zero.
|
||||
} THREADNAME_INFO;
|
||||
#pragma pack(pop)
|
||||
|
||||
static int SetThreadName(DWORD dwThreadID, const char *threadName)
|
||||
{
|
||||
THREADNAME_INFO info;
|
||||
int result;
|
||||
|
||||
info.dwType = 0x1000;
|
||||
info.szName = threadName;
|
||||
info.dwThreadID = dwThreadID;
|
||||
info.dwFlags = 0;
|
||||
|
||||
__try
|
||||
{
|
||||
RaiseException(MS_VC_EXCEPTION, 0,
|
||||
sizeof(info)/sizeof(ULONG_PTR), (ULONG_PTR*)&info);
|
||||
result = 0;
|
||||
}
|
||||
__except(EXCEPTION_EXECUTE_HANDLER)
|
||||
{
|
||||
result = -1;
|
||||
}
|
||||
}
|
||||
|
||||
#define PTHREAD_SETNAME(a,b) SetThreadName(-1, b)
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef PTHREAD_SETNAME
|
||||
#define PTHREAD_SETNAME(a,b) -1
|
||||
#endif
|
||||
|
||||
|
||||
// Some older BSD systems used a non-standard range of thread priorities.
|
||||
// Use these if they exist, otherwise define standard ones.
|
||||
|
@ -749,9 +801,49 @@ unregisterActiveThread(NSThread *thread)
|
|||
return _name;
|
||||
}
|
||||
|
||||
- (void) _setName: (NSString *)aName
|
||||
{
|
||||
int result = -1;
|
||||
|
||||
while (result != 0 && [aName length] > 0)
|
||||
{
|
||||
result = PTHREAD_SETNAME(pthread_self(),
|
||||
[aName cStringUsingEncoding: NSUTF8StringEncoding]);
|
||||
if (result != 0)
|
||||
{
|
||||
if (ERANGE == errno)
|
||||
{
|
||||
/* Name must be too long ... gnu/linix uses 15 characters
|
||||
*/
|
||||
if ([aName length] > 15)
|
||||
{
|
||||
aName = [aName substringToIndex: 15];
|
||||
}
|
||||
else
|
||||
{
|
||||
aName = [aName substringToIndex: [aName length] - 1];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
break; // Some other error
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void) setName: (NSString*)aName
|
||||
{
|
||||
ASSIGN(_name, aName);
|
||||
#ifdef PTHREAD_SETNAME
|
||||
if (YES == _active)
|
||||
{
|
||||
[self performSelector: @selector(_setName:)
|
||||
onThread: self
|
||||
withObject: aName
|
||||
waitUntilDone: NO];
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
- (void) setStackSize: (NSUInteger)stackSize
|
||||
|
@ -806,6 +898,8 @@ static void *nsthreadLauncher(void* thread)
|
|||
object: t
|
||||
userInfo: nil];
|
||||
|
||||
[t _setName: [t name]];
|
||||
|
||||
[t main];
|
||||
|
||||
[NSThread exit];
|
||||
|
|
20
configure.ac
20
configure.ac
|
@ -1743,6 +1743,26 @@ AC_DEFINE_UNQUOTED(HAVE_OBJC_ROOT_CLASS_ATTRIBUTE,$gs_objc_root_class_attr,
|
|||
[Says whether the objc_root_class attribute works])
|
||||
CFLAGS=$saved_CFLAGS
|
||||
|
||||
|
||||
#--------------------------------------------------------------------
|
||||
# Check if we can name pthreads
|
||||
#--------------------------------------------------------------------
|
||||
|
||||
|
||||
AC_CHECK_FUNC(pthread_setname_np, pthread_setname_ok=yes, pthread_setname_ok=no)
|
||||
if test $pthread_setname_ok = yes ; then
|
||||
case "$target_os" in
|
||||
darwin*) AC_DEFINE(PTHREAD_SETNAME(a,b), pthread_setname_np(b), [Description: Define set name function for pthread]);;
|
||||
*) AC_DEFINE(PTHREAD_SETNAME(a,b), pthread_setname_np(a,b), [Description: Define set name function for pthread]);;
|
||||
esac
|
||||
fi
|
||||
|
||||
AC_CHECK_FUNC(pthread_set_name_np, pthread_set_name_ok=yes, pthread_set_name_ok=no)
|
||||
if test $pthread_set_name_ok = yes ; then
|
||||
AC_DEFINE(PTHREAD_SETNAME(a,b), pthread_set_name_np(a,b), [Description: Define set name function for pthread])
|
||||
fi
|
||||
|
||||
|
||||
#--------------------------------------------------------------------
|
||||
# Check whether Objective-C /really/ works
|
||||
#--------------------------------------------------------------------
|
||||
|
|
Loading…
Reference in a new issue