Skip to content

Commit e6f6d0e

Browse files
Posix port - set name for threads (#950)
Co-authored-by: jasonpcarroll <[email protected]>
1 parent 52ab3d0 commit e6f6d0e

File tree

1 file changed

+20
-0
lines changed
  • portable/ThirdParty/GCC/Posix

1 file changed

+20
-0
lines changed

portable/ThirdParty/GCC/Posix/port.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@
5151
*----------------------------------------------------------*/
5252
#include "portmacro.h"
5353

54+
#ifdef __linux__
55+
#define __USE_GNU
56+
#endif
57+
5458
#include <errno.h>
5559
#include <pthread.h>
5660
#include <signal.h>
@@ -134,6 +138,16 @@ void prvFatalError( const char * pcCall,
134138
}
135139
/*-----------------------------------------------------------*/
136140

141+
static void prvPortSetCurrentThreadName(char * pxThreadName)
142+
{
143+
#ifdef __APPLE__
144+
pthread_setname_np(pxThreadName);
145+
#else
146+
pthread_setname_np(pthread_self(), pxThreadName);
147+
#endif
148+
}
149+
/*-----------------------------------------------------------*/
150+
137151
/*
138152
* See header file for description.
139153
*/
@@ -224,6 +238,7 @@ BaseType_t xPortStartScheduler( void )
224238
const ListItem_t * pxEndMarker;
225239

226240
hMainThread = pthread_self();
241+
prvPortSetCurrentThreadName("Scheduler");
227242

228243
/* Start the timer that generates the tick ISR(SIGALRM).
229244
* Interrupts are disabled here already. */
@@ -383,6 +398,8 @@ static void * prvTimerTickHandler( void * arg )
383398
{
384399
( void ) arg;
385400

401+
prvPortSetCurrentThreadName("Scheduler timer");
402+
386403
while( xTimerTickThreadShouldRun )
387404
{
388405
/*
@@ -493,6 +510,9 @@ static void * prvWaitForStart( void * pvParams )
493510
uxCriticalNesting = 0;
494511
vPortEnableInterrupts();
495512

513+
/* Set thread name */
514+
prvPortSetCurrentThreadName(pcTaskGetName(xTaskGetCurrentTaskHandle()));
515+
496516
/* Call the task's entry point. */
497517
pxThread->pxCode( pxThread->pvParams );
498518

0 commit comments

Comments
 (0)