mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-08 22:47:54 +02:00
* fix for Mantis #36950: apply (slightly adjusted) patch by Bi0T1N to implement SetThreadDebugNameA and -U for Linux and Android targets
git-svn-id: trunk@45233 -
This commit is contained in:
parent
3d2945726a
commit
0906714aa4
@ -191,6 +191,7 @@ Type
|
||||
function sem_getvalue (__sem:Psem_t; __sval:Plongint):longint;cdecl;external;
|
||||
|
||||
function pthread_mutexattr_settype (__attr: Ppthread_mutexattr_t; Kind:Integer): Integer; cdecl;external;
|
||||
function pthread_setname_np(thread: pthread_t; name: PAnsiChar):cint;cdecl;external;
|
||||
|
||||
{$else}
|
||||
Var
|
||||
@ -272,6 +273,7 @@ Var
|
||||
sem_getvalue : function (__sem:Psem_t; __sval:Plongint):longint;cdecl;
|
||||
|
||||
pthread_mutexattr_settype : function(__attr: Ppthread_mutexattr_t; Kind:Integer): Integer; cdecl;
|
||||
pthread_setname_np : function(thread: pthread_t; name: PAnsiChar):cint;cdecl;
|
||||
|
||||
|
||||
Var
|
||||
@ -363,6 +365,7 @@ begin
|
||||
Pointer(sem_post ) := dlsym(PthreadDLL,'sem_post');
|
||||
Pointer(sem_getvalue ) := dlsym(PthreadDLL,'sem_getvalue');
|
||||
Pointer(pthread_mutexattr_settype) := dlsym(PthreadDLL,'pthread_mutexattr_settype');
|
||||
Pointer(pthread_setname_np) := dlsym(PthreadDLL,'pthread_setname_np');
|
||||
end;
|
||||
|
||||
Function UnLoadPthreads : Boolean;
|
||||
|
@ -488,14 +488,45 @@ Type PINTRTLEvent = ^TINTRTLEvent;
|
||||
|
||||
|
||||
procedure CSetThreadDebugNameA(threadHandle: TThreadID; const ThreadName: AnsiString);
|
||||
{$if defined(Linux) or defined(Android)}
|
||||
var
|
||||
CuttedName: AnsiString;
|
||||
{$endif}
|
||||
begin
|
||||
{$Warning SetThreadDebugName needs to be implemented}
|
||||
{$if defined(Linux) or defined(Android)}
|
||||
{$ifdef dynpthreads}
|
||||
if Assigned(pthread_setname_np) then
|
||||
{$endif dynpthreads}
|
||||
begin
|
||||
// length restricted to 16 characters including terminating null byte
|
||||
CuttedName:=Copy(ThreadName, 1, 15);
|
||||
if threadHandle=TThreadID(-1) then
|
||||
begin
|
||||
pthread_setname_np(pthread_self(), @CuttedName[1]);
|
||||
end
|
||||
else
|
||||
begin
|
||||
pthread_setname_np(pthread_t(threadHandle), @CuttedName[1]);
|
||||
end;
|
||||
end;
|
||||
{$else}
|
||||
{$Warning SetThreadDebugName needs to be implemented}
|
||||
{$endif}
|
||||
end;
|
||||
|
||||
|
||||
procedure CSetThreadDebugNameU(threadHandle: TThreadID; const ThreadName: UnicodeString);
|
||||
begin
|
||||
{$Warning SetThreadDebugName needs to be implemented}
|
||||
{$if defined(Linux) or defined(Android)}
|
||||
{$ifdef dynpthreads}
|
||||
if Assigned(pthread_setname_np) then
|
||||
{$endif dynpthreads}
|
||||
begin
|
||||
CSetThreadDebugNameA(threadHandle, AnsiString(ThreadName));
|
||||
end;
|
||||
{$else}
|
||||
{$Warning SetThreadDebugName needs to be implemented}
|
||||
{$endif}
|
||||
end;
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user