@@ -51,6 +51,8 @@ typedef struct EtsiSvcCtx {
5151#ifdef WOLFKM_VAULT
5252 wolfVaultCtx * vault ; /* key vault */
5353#endif
54+
55+ byte shutdown :1 ; /* signal to shutdown workers */
5456} EtsiSvcCtx ;
5557static EtsiSvcCtx gSvcCtx ;
5658
@@ -130,6 +132,14 @@ static int EtsiSvcGenNewKey(EtsiSvcCtx* svcCtx, EtsiKeyType keyType, EtsiKey* ke
130132 return ret ;
131133}
132134
135+ static void WakeKeyGenWorker (EtsiSvcCtx * svcCtx )
136+ {
137+ /* signal key generation thread to wake */
138+ pthread_mutex_lock (& svcCtx -> kgMutex );
139+ pthread_cond_signal (& svcCtx -> kgCond );
140+ pthread_mutex_unlock (& svcCtx -> kgMutex );
141+ }
142+
133143static int SetupKeyPackage (SvcConn * conn , EtsiSvcCtx * svcCtx )
134144{
135145 int ret = 0 , i ;
@@ -222,9 +232,7 @@ static int SetupKeyPackage(SvcConn* conn, EtsiSvcCtx* svcCtx)
222232
223233 if (wakeKg ) {
224234 /* signal key generation thread to wake */
225- pthread_mutex_lock (& svcCtx -> kgMutex );
226- pthread_cond_signal (& svcCtx -> kgCond );
227- pthread_mutex_unlock (& svcCtx -> kgMutex );
235+ WakeKeyGenWorker (svcCtx );
228236 }
229237
230238 return ret ;
@@ -318,7 +326,7 @@ static void* KeyPushWorker(void* arg)
318326 pthread_mutex_unlock (& svcCtx -> kgMutex );
319327
320328 XLOG (WOLFKM_LOG_DEBUG , "Key Generation Worker Wake %d sec\n" , ret );
321- } while (1 );
329+ } while (! svcCtx -> shutdown );
322330
323331 return NULL ;
324332}
@@ -581,6 +589,10 @@ void wolfEtsiSvc_Cleanup(SvcInfo* svc)
581589
582590 wc_FreeRng (& svcCtx -> rng );
583591
592+ /* signal shutdown and wake worker */
593+ svcCtx -> shutdown = 1 ;
594+ WakeKeyGenWorker (svcCtx );
595+
584596 pthread_mutex_destroy (& svcCtx -> kgMutex );
585597 pthread_cond_destroy (& svcCtx -> kgCond );
586598
0 commit comments