Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/FreeRTOS/FreeRTOS-Kernel.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChing-Hsin Lee <chinglee@amazon.com>2024-01-10 08:18:55 +0300
committerPaul Bartell <paul.bartell@gmail.com>2024-01-11 21:53:54 +0300
commit7ba4124c785e400cb0e8c3c17a49f390e90ba77e (patch)
tree4efa71f29a39697586a156d1d3b84c0681c6e6df
parent6b698ff6bc539a932b28aa5220fc978a3d585667 (diff)
Add back the pthread stack fit
-rw-r--r--portable/ThirdParty/GCC/Posix/port.c37
1 files changed, 24 insertions, 13 deletions
diff --git a/portable/ThirdParty/GCC/Posix/port.c b/portable/ThirdParty/GCC/Posix/port.c
index 34293f01a..391abe4ff 100644
--- a/portable/ThirdParty/GCC/Posix/port.c
+++ b/portable/ThirdParty/GCC/Posix/port.c
@@ -60,7 +60,6 @@
#include <sys/time.h>
#include <sys/times.h>
#include <time.h>
-#include <unistd.h>
#ifdef __APPLE__
#include <mach/mach_vm.h>
@@ -104,9 +103,10 @@ static sigset_t xAllSignals;
static sigset_t xSchedulerOriginalSignalMask;
static pthread_t hMainThread = ( pthread_t ) NULL;
static volatile BaseType_t uxCriticalNesting;
-static List_t xThreadList;
-static pthread_t hTimerTickThread;
static BaseType_t xSchedulerEnd = pdFALSE;
+static pthread_t hTimerTickThread;
+static uint64_t prvStartTimeNs;
+static List_t xThreadList; /* The list to track all the pthreads which are not deleted. */
/*-----------------------------------------------------------*/
static void prvSetupSignalsAndSchedulerPolicy( void );
@@ -130,6 +130,7 @@ void prvFatalError( const char * pcCall,
fprintf( stderr, "%s: %s\n", pcCall, strerror( iErrno ) );
abort();
}
+/*-----------------------------------------------------------*/
/*
* See header file for description.
@@ -166,13 +167,15 @@ StackType_t * pxPortInitialiseStack( StackType_t * pxTopOfStack,
thread->pvParams = pvParameters;
thread->xDying = pdFALSE;
+ /* Ensure ulStackSize is at least PTHREAD_STACK_MIN */
+ ulStackSize = ( ulStackSize < PTHREAD_STACK_MIN ) ? PTHREAD_STACK_MIN : ulStackSize;
+
pthread_attr_init( &xThreadAttributes );
- iRet = pthread_attr_setstack( &xThreadAttributes, pxEndOfStack, ulStackSize );
+ iRet = pthread_attr_setstacksize( &xThreadAttributes, ulStackSize );
if( iRet != 0 )
{
- fprintf( stderr, "[WARN] pthread_attr_setstack failed with return value: %d. Default stack will be used.\n", iRet );
- fprintf( stderr, "[WARN] Increase the stack size to PTHREAD_STACK_MIN.\n" );
+ fprintf( stderr, "[WARN] pthread_attr_setstacksize failed with return value: %d. Default stack size will be used.\n", iRet );
}
thread->ev = event_create();
@@ -242,13 +245,9 @@ BaseType_t xPortStartScheduler( void )
sigwait( &xSignals, &iSignal );
}
- /*
- * cancel and join any remaining pthreads
- * to ensure their resources are freed
- *
- * https://stackoverflow.com/a/5612424
- */
+ /* Cancel all the running thread. */
pxEndMarker = listGET_END_MARKER( &xThreadList );
+
for( pxIterator = listGET_HEAD_ENTRY( &xThreadList ); pxIterator != pxEndMarker; pxIterator = listGET_NEXT( pxIterator ) )
{
Thread_t *pxThread = ( Thread_t * ) listGET_LIST_ITEM_OWNER( pxIterator );
@@ -258,6 +257,16 @@ BaseType_t xPortStartScheduler( void )
event_delete( pxThread->ev );
}
+ /*
+ * clear out the variable that is used to end the scheduler, otherwise
+ * subsequent scheduler restarts will end immediately.
+ */
+ xSchedulerEnd = pdFALSE;
+
+ /* Reset the pthread_once_t structure. This is required if the port
+ * starts the scheduler again. */
+ hSigSetupThread = PTHREAD_ONCE_INIT;
+
/* Restore original signal mask. */
( void ) pthread_sigmask( SIG_SETMASK, &xSchedulerOriginalSignalMask, NULL );
@@ -362,7 +371,7 @@ static uint64_t prvGetTimeNs( void )
return ( uint64_t ) t.tv_sec * ( uint64_t ) 1000000000UL + ( uint64_t ) t.tv_nsec;
}
-static uint64_t prvStartTimeNs;
+/*-----------------------------------------------------------*/
/* commented as part of the code below in vPortSystemTickHandler,
* to adjust timing according to full demo requirements */
@@ -453,6 +462,7 @@ void vPortThreadDying( void * pxTaskToDelete,
pxThread->xDying = pdTRUE;
}
+/*-----------------------------------------------------------*/
void vPortCancelThread( void * pxTaskToDelete )
{
@@ -542,6 +552,7 @@ static void prvSuspendSelf( Thread_t * thread )
* - A thread with all signals blocked with pthread_sigmask().
*/
event_wait( thread->ev );
+ pthread_testcancel();
}
/*-----------------------------------------------------------*/