Skip to content

Commit 3f9c734

Browse files
bigger equeue generation size and only increment when needed
to mitigate against generation clash
1 parent 0e89f9d commit 3f9c734

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

events/include/events/equeue.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,9 @@ struct equeue_event {
6161
typedef struct equeue {
6262
struct equeue_event *queue;
6363
unsigned tick;
64+
65+
uint16_t generation;
6466
bool break_requested;
65-
uint8_t generation;
6667

6768
unsigned char *buffer;
6869
unsigned npw2;

events/source/equeue.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,8 +351,8 @@ static struct equeue_event *equeue_dequeue(equeue_t *q, unsigned target)
351351
{
352352
equeue_mutex_lock(&q->queuelock);
353353

354-
// find all expired events and mark a new generation
355-
q->generation += 1;
354+
// find all expired events
355+
356356
if (equeue_tickdiff(q->tick, target) <= 0) {
357357
q->tick = target;
358358
}
@@ -370,6 +370,12 @@ static struct equeue_event *equeue_dequeue(equeue_t *q, unsigned target)
370370

371371
*p = 0;
372372

373+
/* we only increment the generation if events have been taken off the queue
374+
* as this is the only time cancellation may conflict with dequeueing */
375+
if (head) {
376+
q->generation += 1;
377+
}
378+
373379
equeue_mutex_unlock(&q->queuelock);
374380

375381
// reverse and flatten each slot to match insertion order

0 commit comments

Comments
 (0)