Skip to content

Commit 675754d

Browse files
authored
Merge pull request #14405 from paul-szczepanek-arm/equeue-fix
Update event queue generation process
2 parents 9cc1f47 + 86f8b0b commit 675754d

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

events/include/events/equeue.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ extern "C" {
4242
// Internal event structure
4343
struct equeue_event {
4444
unsigned size;
45+
uint16_t generation;
4546
uint8_t id;
46-
uint8_t generation;
4747

4848
struct equeue_event *next;
4949
struct equeue_event *sibling;
@@ -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)