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:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user