Prevent race condition when sync req received

Added a flush mechanism to actor thread. This is used to wait for all
waiting jobs in the queue to be completed.
This commit is contained in:
Sakthivel Velumani
2024-12-10 09:51:10 -05:00
parent e5814cd62e
commit 73921dfa10
3 changed files with 26 additions and 2 deletions
+13 -1
View File
@@ -50,7 +50,8 @@ void *actor_thread(void *arg)
break;
}
elt->processingFunc(NotifiedFifoData(elt));
if (elt->processingFunc) // processing function can be NULL
elt->processingFunc(NotifiedFifoData(elt));
if (elt->reponseFifo) {
pushNotifiedFIFO(elt->reponseFifo, elt);
} else
@@ -85,3 +86,14 @@ void shutdown_actor(Actor_t *actor)
abortNotifiedFIFO(&response_fifo);
pthread_join(actor->thread, NULL);
}
void flush_actor(Actor_t *actor)
{
notifiedFIFO_t response_fifo;
initNotifiedFIFO(&response_fifo);
notifiedFIFO_elt_t *elt = newNotifiedFIFO_elt(0, 0, &response_fifo, NULL);
pushNotifiedFIFO(&actor->fifo, elt);
elt = pullNotifiedFIFO(&response_fifo);
delNotifiedFIFO_elt(elt);
abortNotifiedFIFO(&response_fifo);
}
+5
View File
@@ -49,4 +49,9 @@ void destroy_actor(Actor_t *actor);
/// @param actor
void shutdown_actor(Actor_t *actor);
/// @brief This function will return when all current jobs in the queue are finished.
/// The caller should make sure no new jobs are added to the queue between this function call and return.
/// @param actor
void flush_actor(Actor_t *actor);
#endif