bigger equeue generation size and only increment when needed

to mitigate against generation clash
pull/14405/head
Paul Szczepanek 2021-03-09 22:08:43 +00:00
parent 0e89f9d6d9
commit 3f9c734e1a
2 changed files with 10 additions and 3 deletions

View File

@ -61,8 +61,9 @@ struct equeue_event {
typedef struct equeue {
struct equeue_event *queue;
unsigned tick;
uint16_t generation;
bool break_requested;
uint8_t generation;
unsigned char *buffer;
unsigned npw2;

View File

@ -351,8 +351,8 @@ static struct equeue_event *equeue_dequeue(equeue_t *q, unsigned target)
{
equeue_mutex_lock(&q->queuelock);
// find all expired events and mark a new generation
q->generation += 1;
// find all expired events
if (equeue_tickdiff(q->tick, target) <= 0) {
q->tick = target;
}
@ -370,6 +370,12 @@ static struct equeue_event *equeue_dequeue(equeue_t *q, unsigned target)
*p = 0;
/* we only increment the generation if events have been taken off the queue
* as this is the only time cancellation may conflict with dequeueing */
if (head) {
q->generation += 1;
}
equeue_mutex_unlock(&q->queuelock);
// reverse and flatten each slot to match insertion order