From df73aa96e70684e9b209d05ad7c713ba3e0daaa6 Mon Sep 17 00:00:00 2001 From: Alfred Gedeon Date: Fri, 4 Sep 2020 11:23:46 -0700 Subject: [PATCH] Fix: event signal not being reset --- portable/ThirdParty/GCC/Posix/port.c | 18 +++--------------- .../GCC/Posix/utils/wait_for_event.c | 1 + 2 files changed, 4 insertions(+), 15 deletions(-) diff --git a/portable/ThirdParty/GCC/Posix/port.c b/portable/ThirdParty/GCC/Posix/port.c index 0bbc351da..90c048df1 100644 --- a/portable/ThirdParty/GCC/Posix/port.c +++ b/portable/ThirdParty/GCC/Posix/port.c @@ -97,7 +97,6 @@ static sigset_t xResumeSignals; static sigset_t xAllSignals; static sigset_t xSchedulerOriginalSignalMask; static pthread_t hMainThread = ( pthread_t )NULL; -static Thread_t *main_thread; static volatile portBASE_TYPE uxCriticalNesting; /*-----------------------------------------------------------*/ @@ -135,6 +134,7 @@ static void vPortStartFirstTask( void ); * timer (SIGALRM) and other signals. */ +/* extern void *__libc_malloc(size_t); extern void __libc_free(void *); extern void *__libc_calloc(size_t, size_t); @@ -183,6 +183,7 @@ sigset_t xSavedSignals; return ptr; } +*/ static void prvFatalError( const char *pcCall, int iErrno ) { @@ -253,7 +254,6 @@ int iSignal; sigset_t xSignals; hMainThread = pthread_self(); - main_thread = prvGetThreadFromTask( xTaskGetCurrentTaskHandle() ); /* Start the timer that generates the tick ISR. Interrupts are disabled here already. */ @@ -268,9 +268,7 @@ sigset_t xSignals; while ( !xSchedulerEnd ) { - // event_wait(main_thread->ev); sigwait( &xSignals, &iSignal ); - //sleep(1); } /* Restore original signal mask. */ @@ -301,8 +299,7 @@ struct sigaction sigtick; /* Signal the scheduler to exit its loop. */ xSchedulerEnd = pdTRUE; -// (void)pthread_kill( hMainThread, SIG_RESUME ); -// event_signal(main_thread->ev); + (void)pthread_kill( hMainThread, SIG_RESUME ); //prvSuspendSelf(); } @@ -483,7 +480,6 @@ static void *prvWaitForStart( void * pvParams ) { Thread_t *pxThread = pvParams; - printf("wait for start %lu\n", pxThread->pthread); prvSuspendSelf(pxThread); /* Resumed for the first time, unblocks all signals. */ @@ -513,7 +509,6 @@ BaseType_t uxSavedCriticalNesting; */ uxSavedCriticalNesting = uxCriticalNesting; - printf("stopping %lu resuming %lu\n",pxThreadToSuspend->pthread ,pxThreadToResume->pthread); prvResumeThread( pxThreadToResume ); if ( pxThreadToSuspend->xDying ) { @@ -521,7 +516,6 @@ BaseType_t uxSavedCriticalNesting; } prvSuspendSelf( pxThreadToSuspend ); - printf("thread continuing %lu\n", pxThreadToResume->pthread); uxCriticalNesting = uxSavedCriticalNesting; } @@ -545,11 +539,7 @@ int iSig; * * - A thread with all signals blocked with pthread_sigmask(). */ - printf("Suspending thread: %lu \n", thread->pthread); - //vPortDisableInterrupts(); event_wait(thread->ev); - //vPortEnableInterrupts(); - //sigwait( &xResumeSignals, &iSig ); } /*-----------------------------------------------------------*/ @@ -559,7 +549,6 @@ static void prvResumeThread( Thread_t *xThreadId ) if ( pthread_self() != xThreadId->pthread ) { event_signal(xThreadId->ev); -// pthread_kill( xThreadId->pthread, SIG_RESUME ); } } /*-----------------------------------------------------------*/ @@ -570,7 +559,6 @@ struct sigaction sigresume, sigtick; int iRet; hMainThread = pthread_self(); - main_thread = prvGetThreadFromTask( xTaskGetCurrentTaskHandle() ); /* Initialise common signal masks. */ sigemptyset( &xResumeSignals ); diff --git a/portable/ThirdParty/GCC/Posix/utils/wait_for_event.c b/portable/ThirdParty/GCC/Posix/utils/wait_for_event.c index 6d0bfffda..896604a53 100644 --- a/portable/ThirdParty/GCC/Posix/utils/wait_for_event.c +++ b/portable/ThirdParty/GCC/Posix/utils/wait_for_event.c @@ -37,6 +37,7 @@ bool event_wait( struct event * ev ) pthread_cond_wait( &ev->cond, &ev->mutex ); } + ev->event_triggered = false; pthread_mutex_unlock( &ev->mutex ); return true; }